With the C preprocessor you can have some kind of high-order macros. Something like this:
#define ABC(f) f(a) f(b) f(c)
#define XY(f) f(x) f(y)
#define CODE(x) foo_ ## x
ABC(CODE)
#undef CODE
#define CODE(x) bar_ ## x
XY(CODE)
#undef CODE
The output is:
foo_a foo_b foo_c
bar_x bar_y
Is there some trick to nest such iterations, to do something like this?
#define CODE(x) foo_ ## x
NEST(ABC, XY, CODE)
#undef CODE
So the output would be:
foo_ax foo_ay foo_bx foo_by foo_cx foo_cy
In particular, I'd like to have the definitions of ABC
and XY
independent from each other, so that I can still use ABC
stand-alone or maybe do even something like this:
#define CODE(x) foo_ ## x
NEST(XY, KLMN, ABC, CODE)
#undef CODE
For the record, here the solution:
#include <boost/preprocessor/seq.hpp>
#define ABC (a) (b) (c)
#define XY (x) (y)
#define CODE(r, prod) BOOST_PP_CAT(foo_, BOOST_PP_SEQ_CAT(prod))
BOOST_PP_SEQ_FOR_EACH_PRODUCT(CODE, (ABC) (XY))
Yields:
foo_ax foo_ay foo_bx foo_by foo_cx foo_cy