
20 Sep
2014
20 Sep
'14
1:35 p.m.
Hi all, I'm trying to use BOOST_PP to generate some code. I can generate the sequence int x_0 to int x_4 using the code below. #include <boost/preprocessor/repetition/repeat.hpp> #define DECL1(z, n, text) text ## _ ## n = n; #define decl1(text, count) BOOST_PP_REPEAT(count, DECL1, text) decl1 (int x, 5) What I'd like to do is write a decl2 that can be used something like this: decl2 (int x, 5, 2) to generate int x_0_0 to int x_4_1 I've tried nesting BOOST_PP_REPEAT but so far I've been unable to produce the desired behaviour unless I hardcode one of the iteration counts. I'd like to also eventually write a decl3(int x, 5, 3, 4) when I understand how a decl2 would work. Any help much appreciated! Regards, Colin