proxygen
Preprocessor.h File Reference

Go to the source code of this file.

Macros

#define FB_VA_GLUE(a, b)   a b
 
#define FB_ONE_OR_NONE(a, ...)   FB_VA_GLUE(FB_THIRD, (a, ##__VA_ARGS__, a))
 
#define FB_THIRD(a, b, ...)   __VA_ARGS__
 
#define FB_ARG_1(a, ...)   a
 
#define FB_ARG_2_OR_1(...)   FB_ARG_2_OR_1_IMPL(__VA_ARGS__, __VA_ARGS__)
 
#define FB_ARG_2_OR_1_IMPL(a, b, ...)   b
 
#define FB_SINGLE_ARG(...)   __VA_ARGS__
 
#define FOLLY_PP_DETAIL_APPEND_VA_ARG(...)   , ##__VA_ARGS__
 
#define FOLLY_IGNORE(...)
 
#define FOLLY_SEMICOLON(...)   ;
 
#define FB_CONCATENATE_IMPL(s1, s2)   s1##s2
 
#define FB_CONCATENATE(s1, s2)   FB_CONCATENATE_IMPL(s1, s2)
 
#define FB_ANONYMOUS_VARIABLE(str)   FB_CONCATENATE(str, __LINE__)
 
#define FB_STRINGIZE(x)   #x
 
#define FOLLY_PP_DETAIL_NARGS_1(dummy, _7, _6, _5, _4, _3, _2, _1, _0, ...)   _0
 
#define FOLLY_PP_DETAIL_NARGS(...)   FOLLY_PP_DETAIL_NARGS_1(dummy, ##__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0)
 
#define FOLLY_PP_DETAIL_FOR_EACH_REC_0(fn, ...)
 
#define FOLLY_PP_DETAIL_FOR_EACH_REC_1(fn, a, ...)   fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_0(fn, __VA_ARGS__)
 
#define FOLLY_PP_DETAIL_FOR_EACH_REC_2(fn, a, ...)   fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_1(fn, __VA_ARGS__)
 
#define FOLLY_PP_DETAIL_FOR_EACH_REC_3(fn, a, ...)   fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_2(fn, __VA_ARGS__)
 
#define FOLLY_PP_DETAIL_FOR_EACH_REC_4(fn, a, ...)   fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_3(fn, __VA_ARGS__)
 
#define FOLLY_PP_DETAIL_FOR_EACH_REC_5(fn, a, ...)   fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_4(fn, __VA_ARGS__)
 
#define FOLLY_PP_DETAIL_FOR_EACH_REC_6(fn, a, ...)   fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_5(fn, __VA_ARGS__)
 
#define FOLLY_PP_DETAIL_FOR_EACH_REC_7(fn, a, ...)   fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_6(fn, __VA_ARGS__)
 
#define FOLLY_PP_DETAIL_FOR_EACH_2(fn, n, ...)   FOLLY_PP_DETAIL_FOR_EACH_REC_##n(fn, __VA_ARGS__)
 
#define FOLLY_PP_DETAIL_FOR_EACH_1(fn, n, ...)   FOLLY_PP_DETAIL_FOR_EACH_2(fn, n, __VA_ARGS__)
 
#define FOLLY_PP_FOR_EACH(fn, ...)
 

Macro Definition Documentation

#define FB_ANONYMOUS_VARIABLE (   str)    FB_CONCATENATE(str, __LINE__)

Definition at line 92 of file Preprocessor.h.

#define FB_ARG_1 (   a,
  ... 
)    a

Helper macro that extracts the first argument out of a list of any number of arguments.

Definition at line 41 of file Preprocessor.h.

#define FB_ARG_2_OR_1 (   ...)    FB_ARG_2_OR_1_IMPL(__VA_ARGS__, __VA_ARGS__)

Helper macro that extracts the second argument out of a list of any number of arguments. If only one argument is given, it returns that.

Definition at line 54 of file Preprocessor.h.

Referenced by folly::sync_tests::testDeprecated().

#define FB_ARG_2_OR_1_IMPL (   a,
  b,
  ... 
)    b

Definition at line 57 of file Preprocessor.h.

#define FB_CONCATENATE (   s1,
  s2 
)    FB_CONCATENATE_IMPL(s1, s2)

Definition at line 88 of file Preprocessor.h.

#define FB_CONCATENATE_IMPL (   s1,
  s2 
)    s1##s2

FB_ANONYMOUS_VARIABLE(str) introduces an identifier starting with str and ending with a number that varies with the line.

Definition at line 87 of file Preprocessor.h.

#define FB_ONE_OR_NONE (   a,
  ... 
)    FB_VA_GLUE(FB_THIRD, (a, ##__VA_ARGS__, a))

FB_ONE_OR_NONE(hello, world) expands to hello and FB_ONE_OR_NONE(hello) expands to nothing. This macro is used to insert or eliminate text based on the presence of another argument.

Definition at line 34 of file Preprocessor.h.

#define FB_SINGLE_ARG (   ...)    __VA_ARGS__

Helper macro that provides a way to pass argument with commas in it to some other macro whose syntax doesn't allow using extra parentheses. Example:

#define MACRO(type, name) type name MACRO(FB_SINGLE_ARG(std::pair<size_t, size_t>), x);

Definition at line 68 of file Preprocessor.h.

#define FB_STRINGIZE (   x)    #x

Use FB_STRINGIZE(x) when you'd want to do what x does inside another macro expansion.

Definition at line 100 of file Preprocessor.h.

#define FB_THIRD (   a,
  b,
  ... 
)    __VA_ARGS__

Definition at line 35 of file Preprocessor.h.

#define FB_VA_GLUE (   a,
  b 
)    a b

Necessarily evil preprocessor-related amenities.

Definition at line 27 of file Preprocessor.h.

#define FOLLY_IGNORE (   ...)

Helper macro that just ignores its parameters.

Definition at line 75 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_APPEND_VA_ARG (   ...)    , ##__VA_ARGS__

Definition at line 70 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_1 (   fn,
  n,
  ... 
)    FOLLY_PP_DETAIL_FOR_EACH_2(fn, n, __VA_ARGS__)

Definition at line 124 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_2 (   fn,
  n,
  ... 
)    FOLLY_PP_DETAIL_FOR_EACH_REC_##n(fn, __VA_ARGS__)

Definition at line 122 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_REC_0 (   fn,
  ... 
)

Definition at line 106 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_REC_1 (   fn,
  a,
  ... 
)    fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_0(fn, __VA_ARGS__)

Definition at line 107 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_REC_2 (   fn,
  a,
  ... 
)    fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_1(fn, __VA_ARGS__)

Definition at line 109 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_REC_3 (   fn,
  a,
  ... 
)    fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_2(fn, __VA_ARGS__)

Definition at line 111 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_REC_4 (   fn,
  a,
  ... 
)    fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_3(fn, __VA_ARGS__)

Definition at line 113 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_REC_5 (   fn,
  a,
  ... 
)    fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_4(fn, __VA_ARGS__)

Definition at line 115 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_REC_6 (   fn,
  a,
  ... 
)    fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_5(fn, __VA_ARGS__)

Definition at line 117 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_FOR_EACH_REC_7 (   fn,
  a,
  ... 
)    fn(a) FOLLY_PP_DETAIL_FOR_EACH_REC_6(fn, __VA_ARGS__)

Definition at line 119 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_NARGS (   ...)    FOLLY_PP_DETAIL_NARGS_1(dummy, ##__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0)

Definition at line 103 of file Preprocessor.h.

#define FOLLY_PP_DETAIL_NARGS_1 (   dummy,
  _7,
  _6,
  _5,
  _4,
  _3,
  _2,
  _1,
  _0,
  ... 
)    _0

Definition at line 102 of file Preprocessor.h.

#define FOLLY_PP_FOR_EACH (   fn,
  ... 
)
Value:
fn, FOLLY_PP_DETAIL_NARGS(__VA_ARGS__), __VA_ARGS__)
#define FOLLY_PP_DETAIL_FOR_EACH_1(fn, n,...)
Definition: Preprocessor.h:124
#define FOLLY_PP_DETAIL_NARGS(...)
Definition: Preprocessor.h:103

FOLLY_PP_FOR_EACH

Used to invoke a preprocessor macro, the name of which is passed as the first argument, once for each subsequent variadic argument.

At present, supports [0, 8) arguments.

This input:

#define DOIT(a) go_do_it(a); FOLLY_PP_FOR_EACH(DOIT, 3, 5, 7) #undef DOIT

Expands to this output (with whitespace adjusted for clarity):

go_do_it(3); go_do_it(5); go_do_it(7);

Definition at line 147 of file Preprocessor.h.

#define FOLLY_SEMICOLON (   ...)    ;

Helper macro that just ignores its parameters and inserts a semicolon.

Definition at line 80 of file Preprocessor.h.