Map and Product

There are often mulitple flavors of the map and product macros signified by the EVAL and SEQ components in the macro name. EVAL indicates that the macro recursively expands the result which is typically the desired result. SEQ indicates the the macro operates on sequences as opposed to lists.

Map

CORE_PP_EVAL_MAP(m, first, ...)

Expands to the macro m applied to each of the remaining arguments.

#define DOUBLER(x) x x
CORE_PP_EVAL_MAP(DOUBLER, 1, 2, 3) // 1 1 2 2 3 3

CORE_PP_EVAL_MAP_SEQ(m, seq)

Expands to the macro m applied to each element of the given sequence.

CORE_PP_EVAL_MAP_SEQ(CORE_PP_HEAD, ((1, 2), (2, 3))) // 1 2

CORE_PP_EVAL_MAPN(m, first, ...)

Expands to the macro m prepended to each argument in turn.

CORE_PP_EVAL_MAPN(int, a, b, c) // int a int b int c

CORE_PP_EVAL_MAPN_SEQ(m, seq)

Expands to the first element of the given sequence prepended to each remianing element of the sequence in turn.

CORE_PP_EVAL_MAPN_SEQ((int, a, b, c)) // int a int b int c

CORE_PP_EVAL_MAP_INFIX(m, infix, first, ...)

Expands to the given macro m applied to each of the arguments starting with first interspersed with the macro infix.

#define DOUBLER(x) x x
CORE_PP_MAP_INFIX(DOUBLER, CORE_PP_COMMA, a, b, c) // a a , b b , c c

CORE_PP_EVAL_MAP_INFIX_SEQ(m, infix, seq)

Expands to the given macro m applied to each of the arguments starting with first interspersed with the macro infix.

CORE_PP_MAP_INFIX_SEQ(SECOND_SEQ, CORE_PP_COMMA, ((a 1), (b 2), (c 3))) // 1 , 2 , 3

CORE_PP_EVAL_MAP_WITH(m, data, first, ...)

Expands to the given macro invoked with the given data paired with each subsequent argument in turn.

#define QUALIFY(name, value) name::value
CORE_PP_EVAL_MAP_WITH(QUALITY, Foo, a, b, c) // Foo::a , Foo::b , Foo::c

CORE_PP_EVAL_MAP_WITH_SEQ(m, data, seq)

Expands to the given macro invoked with the given data paired with each element of the given sequence in turn.

#define QUALIFY(name, seq) name::SECOND_SEQ(seq),
COre_PP_EVAL_MAP_WITH_SEQ(QUALIFY, Foo, ((1, a), (2, b), (3, c))) // Foo::a, Foo::b, Foo::c

Product

CORE_PP_EVAL_CARTESIAN_PRODUCT_SEQ(aseq, bseq)

Expands to a sequence of sequences representing the cartesian product of the two given sequences.

CORE_PP_EVAL_CARTESIAN_PRODUCT_SEQ((a,b,c),(1,2)) // ((a,1),(a,2),(b,1),(b,2),(c,1),(c,2))