0%

Macro Detection

1
2
3
4
5
6
7
8
9
10
11
12
13
#define __IGNORE(...)			// abandon the arguments
#define __KEEP(...) __VA_ARGS__ // transmit the arguments
#define IFNDEF(macro, ...) MUXNDEF(macro, __KEEP, __IGNORE)(__VA_ARGS__)
// transmit or abandon the arguments depending on whether the macro is defined
#define __P_DEF_0 X,
#define __P_DEF_1 X,
#define MUXNDEF(macro, X, Y) MUX_MACRO_PROPERTY(__P_DEF_, macro, Y, X)
#define MUX_MACRO_PROPERTY(p, macro, a, b) MUX_WITH_COMMA(concat(p, macro), a, b)
// if macro is defined, transmit "__P_DEF_0" or "__P_DEF_1" as "X, "
#define MUX_WITH_COMMA(contain_comma, a, b) CHOOSE2nd(contain_comma a, b)
#define CHOOSE2nd(a, b, ...) b
// then it's CHOOSE2nd(X, a, b) => a => __IGNORE
// otherwise it's CHOOSE2nd(contain_comma a, b) => b => __KEEP