I want to write the C macros which takes either an integer literal or something akin to an integer literal, and the name of another macro, and expands that other macro as many times as the value of the integer literal, with the index as an argument, e.g.
MAGIC(4, FUN)
expands to
FUN(0) FUN(1) FUN(2) FUN(3)
If, instead, I would have MORE_MAGIC which takes a range start and length, that would be even nicer:
e.g.
MORE_MAGIC(1, 3, FUN)
expands to
FUN(1) FUN(2) FUN(3)
Note:
Boost Preprocessor is an extensive library, focusing on such pre-processor magic.
It offers a macro called BOOST_PP_REPEAT_FROM_TO, which does exactly what you want.
Full reference is available here:
http://boost.org/libs/preprocessor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With