🧑💻 MAP macro for axis lists, etc. (#24191)
This commit is contained in:
@@ -712,13 +712,22 @@
|
||||
#define RREPEAT2_S(S,N,OP,V...) EVAL1024(_RREPEAT2(S,SUB##S(N),OP,V))
|
||||
#define RREPEAT2(N,OP,V...) RREPEAT2_S(0,N,OP,V)
|
||||
|
||||
// See https://github.com/swansontec/map-macro
|
||||
#define MAP_OUT
|
||||
#define MAP_END(...)
|
||||
#define MAP_GET_END() 0, MAP_END
|
||||
#define MAP_NEXT0(test, next, ...) next MAP_OUT
|
||||
#define MAP_NEXT1(test, next) MAP_NEXT0 (test, next, 0)
|
||||
#define MAP_NEXT(test, next) MAP_NEXT1 (MAP_GET_END test, next)
|
||||
#define MAP0(f, x, peek, ...) f(x) MAP_NEXT (peek, MAP1) (f, peek, __VA_ARGS__)
|
||||
#define MAP1(f, x, peek, ...) f(x) MAP_NEXT (peek, MAP0) (f, peek, __VA_ARGS__)
|
||||
#define MAP(f, ...) EVAL512 (MAP1 (f, __VA_ARGS__, (), 0))
|
||||
// Call OP(A) with each item as an argument
|
||||
#define _MAP(_MAP_OP,A,V...) \
|
||||
_MAP_OP(A) \
|
||||
IF_ELSE(HAS_ARGS(V)) \
|
||||
( DEFER2(__MAP)()(_MAP_OP,V) ) \
|
||||
( /* Do nothing */ )
|
||||
#define __MAP() _MAP
|
||||
|
||||
#define MAP(OP,V...) EVAL(_MAP(OP,V))
|
||||
|
||||
// Emit a list of OP(A) with the given items
|
||||
#define _MAPLIST(_MAP_OP,A,V...) \
|
||||
_MAP_OP(A) \
|
||||
IF_ELSE(HAS_ARGS(V)) \
|
||||
( , DEFER2(__MAPLIST)()(_MAP_OP,V) ) \
|
||||
( /* Do nothing */ )
|
||||
#define __MAPLIST() _MAPLIST
|
||||
|
||||
#define MAPLIST(OP,V...) EVAL(_MAPLIST(OP,V))
|
||||
|
||||
Reference in New Issue
Block a user