#define EVAL0(...) __VA_ARGS__
#define MAP_END(...)
#define MAP_OUT
#define EMPTY()
#define DEFER(id) id EMPTY()
#define MAP_NEXT(test, next) next MAP_OUT
#define MAP0_UD_I(f, x, peek, ...) f(x) DEFER ( MAP_NEXT(peek, MAP1_UD_I) ) ( f, peek, __VA_ARGS__ )
#define MAP1_UD_I(f, x, peek, ...) f(x) DEFER ( MAP_NEXT(peek, MAP0_UD_I) ) ( f, peek, __VA_ARGS__ )
/**
* Applies the function macro `f` to each of the remaining parameters, passes userdata as the second parameter to each invocation,
* and the index of the invocation as the third parameter,
* e.g. MAP_UD_I(f, x, a, b, c) evaluates to f(a, x, 0) f(b, x, 1) f(c, x, 2)
*/
#define MAP_UD_I(f, ...) EVAL0(MAP1_UD_I(f, 0, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
/* Pass user-defined data and an index to each invocation */
#define PRINT_STREAM_I(x) printf ("d: d\n");
MAP_UD_I(PRINT_STREAM_I, 1, 2, 3, 4, 5)
Fails with stack overflow. Should fail with preprocessor error
Fails with stack overflow. Should fail with preprocessor error