Hello,
I'm trying to make a macro for the following case (essentially, I have to translate a run-time decision to a compile-time one):
switch(i)
{
case 1: my_func(arg, offsetof(my_struct, arr[1].my_field))); break;
case 2: my_func(arg, offsetof(my_struct, arr[2].my_field))); break;
// etc. up to 10
}
If I could hard-code the whole function call into the macro, I could do something like this:
#define EXPR(unused, x, text) my_func(arg, offsetof(my_struct, arr[x].my_field))); break;
#define MY_MACRO(x) \
switch(x)\
{\
BOOST_PP_REPEAT(x, EXPR, _)\
}
However, I'd like to pass "arg" and "my_field" as parameters to this macro.
What would be the right way to do this?
Thanks.