I would like to construct a macro that takes a variable number of arguments and distributes the first argument to each of the subsequent in a format similar to the examples shown below:
Call: MACRO(F,A)
Result: F:A
Call: MACRO(F,A,B,C)
Result: F:A F:B F:C
I have seen https://github.com/swansontec/map-macro and the general concept of the recursion workaround through:
#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 (EVAL4 (EVAL4 (__VA_ARGS__)))
But I cannot wrap my mind around how to apply this to my problem. Can anyone provide an example to achieve the results shown above? Thanks!
With Boost.PP:
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/variadic/to_seq.hpp>
#define TRANSFORM(r, data, elem) data:elem
#define MACRO(F, ...) \
BOOST_PP_SEQ_FOR_EACH(TRANSFORM, F, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
Demo. This will (AFAIR) work for up to 255 arguments.
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