map-macro icon indicating copy to clipboard operation
map-macro copied to clipboard

utilize __VA_OPT__

Open nopeslide opened this issue 4 years ago • 1 comments

when using __VA_OPT__ you can make this even more compact

#define EVAL0(...) __VA_ARGS__
#define EVAL1(...) EVAL0( EVAL0 ( EVAL0 ( __VA_ARGS__ )))
#define EVAL2(...) EVAL1( EVAL1 ( EVAL1 ( __VA_ARGS__ )))
#define EVAL3(...) EVAL2( EVAL2 ( EVAL2 ( __VA_ARGS__ )))
#define EVAL4(...) EVAL3( EVAL3 ( EVAL3 ( __VA_ARGS__ )))
#define EVAL(...) EVAL4(__VA_ARGS__)

#define NOP
#define MAP_POP0(F,X,...) F(X) __VA_OPT__(MAP_POP1 NOP (F,__VA_ARGS__))
#define MAP_POP1(F,X,...) F(X) __VA_OPT__(MAP_POP0 NOP (F,__VA_ARGS__))

#define MAP(F,...) __VA_OPT__(EVAL (MAP_POP0(F, __VA_ARGS__)))


MAP(F,1,2,3,4,5,6,7,8,9,10)

nopeslide avatar Nov 21 '20 14:11 nopeslide

this also fixes #9

nopeslide avatar Nov 21 '20 14:11 nopeslide