BOOST_PP_REPEAT with internal macro problem

Hi, BOOST_PP_REPEAT works great for me when used like: #define MAX 5 #define CODE my_code_goes_here BOOST_PP_REPEAT(MAX, CODE, ) But it gets confused when used like: #define MAX (4+1) Is ther a work around ? I even tried: #define MAX (4+1) const int myMax=MAX; BOOST_PP_REPEAT(myMax, CODE , ) but still no luck. Any help ? Thanks Yossi

<Yossi.Itzkovich@ecitele.com> wrote
BOOST_PP_REPEAT works great for me when used like:
#define MAX 5 #define CODE my_code_goes_here BOOST_PP_REPEAT(MAX, CODE, )
But it gets confused when used like:
#define MAX (4+1)
Is ther a work around ?
#define MAX BOOST_PP_INC(4) or #define MAX BOOST_PP_ADD(4, 1)
I even tried: #define MAX (4+1) const int myMax=MAX; BOOST_PP_REPEAT(myMax, CODE , )
myMax is a compile-time constant which is not available to the preprocessor, that's why it doesn't work. HTH, Arkadiy

Have you tried: #define MAX ((4+1)) ie add an extra set of brackets? Mathew ----- Original Message ----- From: <Yossi.Itzkovich@ecitele.com> To: <boost@lists.boost.org> Sent: Thursday, July 15, 2004 12:30 PM Subject: [boost] BOOST_PP_REPEAT with internal macro problem
Hi,
BOOST_PP_REPEAT works great for me when used like:
#define MAX 5 #define CODE my_code_goes_here BOOST_PP_REPEAT(MAX, CODE, )
But it gets confused when used like:
#define MAX (4+1)
Is ther a work around ?
I even tried: #define MAX (4+1) const int myMax=MAX; BOOST_PP_REPEAT(myMax, CODE , )
but still no luck.
Any help ?
Thanks
Yossi
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

-----Original Message----- [mailto:boost-bounces@lists.boost.org] On Behalf Of
BOOST_PP_REPEAT works great for me when used like:
#define MAX 5 #define CODE my_code_goes_here BOOST_PP_REPEAT(MAX, CODE, ) ^^ Passing nothing as a macro argument is undefined in C++. You should use a dummie argument instead--preferably not an identifier. I usually use ~ or ?.
But it gets confused when used like:
#define MAX (4+1)
Arkadiy is correct. The library cannot understand the expression (4+1). It can only understand unadorned integer literals (such as 1, 2, 3, etc.) from 0 to 256. If you need to do arithmetic, you have to use the arithmetic primitives of the library, such as BOOST_PP_ADD or, in this case, BOOST_PP_INC (which is more efficient). Thus, if you want to do a repetition of MAX + 1, you need to say: BOOST_PP_REPEAT(BOOST_PP_INC(MAX), CODE, ~) Regards, Paul Mensonides
participants (4)
-
Arkadiy Vertleyb
-
Mathew Robertson
-
Paul Mensonides
-
Yossi.Itzkovich@ecitele.com