Macros for writing macros#
Create a string literal#
-
LITERAL_STRINGIZE(TEXT)#
Evaluates as a string literal containing
TEXT
, without performing macro expansion.Example
Evaluates to:LITERAL_STRINGIZE(__LINE__)
"__LINE__"
- Since
0.2
- Parameters:
TEXT – doesn’t even have to be valid C !
-
STRINGIZE(EXPRESSION)#
Evaluates as a string literal containing
EXPRESSION
with its macros expanded.Example
May evaluate to:STRINGIZE(__LINE__)
"21"
- Since
0.2
- Parameters:
EXPRESSION – doesn’t even have to be valid C !
Combine tokens#
-
LITERAL_CONCAT(TEXT1, TEXT2)#
Evaluates as a single identifier token, that is
TEXT1
concatenated withTEXT2
, not evaluating any macro inside.Example
Evaluates to:LITERAL_CONCAT(temp, __COUNTER__)
temp__COUNTER__
- Since
0.2
-
CONCAT(EXPRESSION1, EXPRESSION2)#
Evaluates as a single identifier token, that is the evaluation of
EXPRESSION1
concatenated with the evaluation ofEXPRESSION2
.Example
May evaluate to:CONCAT(temp, __COUNTER__)
temp0
- Since
0.2
Count arguments#
Fold#
Apply a binary macro on any number of argument.
Configuration
-
FOLD#
Default fold to use, can be overridden.
Defines
-
TREE_FOLD(M, ...)#
Apply the binary macro
M
on pairs of inputs, in a tree-like fashion.Example
expands to:TREE_FOLD(F, A, B, C, D)
F(F(A, B), F(C, D))
- Since
0.2
-
FOLD_RIGHT(M, ...)#
Apply the binary macro
M
on pairs of inputs, first grouping the right-most arguments.Example
expands to:FOLD_RIGHT(F, A, B, C, D)
F(A, F(B, F(C, D)))
- Since
0.2
Iteration#
Generate code by calling a macro repeatedly.
Defines
-
FOR(LIST, MACRO, ...)#
Call
MACRO
on each item of theLIST
, forwarding extra arguments if any.Example
will expand to:FOR(EACH(A, B, C), F, X, Y)
F(X, Y, A) F(X, Y, B) F(X, Y, C)
- Since
0.2
- Parameters:
LIST – shall be of the form
EACH(P0, P1, ..., Pn-1)
MACRO – shall be a function-like macro
Manipulate pairs#
Manipulate pairs.