Boost logo

Boost Users :

Subject: [Boost-users] [preprocessor] BOOST_PP_REPEAT with multiple "data"
From: Igor R (boost.lists_at_[hidden])
Date: 2014-05-28 09:53:51


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.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net