1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#define EXPAND_0(...) __VA_ARGS__
#define EXPAND_1(...) EXPAND_0(EXPAND_0(__VA_ARGS__))
#define EXPAND_2(...) EXPAND_1(EXPAND_1(__VA_ARGS__))
#define EXPAND(...) EXPAND_2(EXPAND_2(__VA_ARGS__))
#define NOTHING
#define STOP(...)
#define IS_END_OF_LIST(...) _, STOP
#define NEXT(test, next) NEXT1(IS_END_OF_LIST test, next)
#define NEXT0(test, next, ...) next
#define NEXT1(test, next) NEXT0(test, next, _)
#define TRANSFORM0(f, x, next, ...) \
f(x) NEXT(next, TRANSFORM1) NOTHING (f, next, __VA_ARGS__)
#define TRANSFORM1(f, x, next, ...) \
f(x) NEXT(next, TRANSFORM0) NOTHING (f, next, __VA_ARGS__)
#define TRANSFORM(f, ...) \
EXPAND(TRANSFORM1(f, __VA_ARGS__, (end of arguments), _))
#define EVENT(x) void x;
#define DECLARE_EVENTS(...) TRANSFORM(EVENT, __VA_ARGS__)
DECLARE_EVENTS(hello(), hey(int x), world())
| |