Hi,

I am trying to use the preprocessor library to simplify the code I have.

The problem:
I have many lines of the following assignments:

mybfclass x_0_mybf;
mybfclass x_1_mybf;
...
mybfclass1 x_0_mybf1;
mybfclass1 x_1_mybf1;
...
mybfclass2 x_0_mybf2;
mybfclass2 x_1_mybf2;

then I defined several vectors:

vector<mybfclass*> x_mybf;
vector<mybfclass1*> x_mybf1;
vector<mybfclass2*> x_mybf2;

use the boost preprocessor library, I write the following code:

#define
DECLX_mybf(z, n, text) BOOST_PP_CAT(text, BOOST_PP_CAT(_, mybf)).push_back(&BOOST_PP_CAT(text, BOOST_PP_CAT(BOOST_PP_CAT(_, n), BOOST_PP_CAT(_, mybf))));
#define DECLX_mybf1(z, n, text) BOOST_PP_CAT(text, BOOST_PP_CAT(_, mybf)).push_back(&BOOST_PP_CAT(text, BOOST_PP_CAT(BOOST_PP_CAT(_, n), BOOST_PP_CAT(_, mybf))));
#define DECLX_mybf2(z, n, text) BOOST_PP_CAT(text, BOOST_PP_CAT(_, mybf)).push_back(&BOOST_PP_CAT(text, BOOST_PP_CAT(BOOST_PP_CAT(_, n), BOOST_PP_CAT(_, mybf))));

BOOST_PP_REPEAT_FROM_TO(0, 2, DECLX_mybf, x);
// generated: x_mybf.push_back(&x_0_mybf); x_mybf.push_back(&x_1_mybf);
BOOST_PP_REPEAT_FROM_TO(0, 2, DECLX_mybf1, x);
// generated: x_mybf1.push_back(&x_0_mybf1); x_mybf1.push_back(&x_1_mybf);
BOOST_PP_REPEAT_FROM_TO(0, 2, DECLX_mybf2, x);
// generated: x_mybf2.push_back(&x_0_mybf2); x_mybf2.push_back(&x_1_mybf);

but I think it is too much coding here, since I have to write a macro for each mybf occurrence, DECLX_mybf

I have difficulty to use the BOOST_PP_REPEAT_FROM_TO for two argument, since the macro(z, x, data) can only accept one argument data, however, I need to pass two arguments x and mybf to the macro,
in order to generate a mybfclass1 x_0_mybf.

does anyone know how to apply macro to generate the above structure?

thanks.

/Kenny