[Preprocessor] Comma in sequence element
I have following code:
#include
On Tue, Feb 12, 2013 at 9:53 AM, Adam Badura
I have following code:
#include
#include template< int I, int J > struct Base { };
#define SEQ ( 1 ) ( 2 ) ( 3 ) ( 4 )
#define OP( s, data, elem ) Base< elem, elem >
Try something like #define OP(s, data, elem) (Base< elem)(elem >) and...
struct Derived : BOOST_PP_SEQ_ENUM( BOOST_PP_SEQ_TRANSFORM( OP, nil, SEQ ) ) { };
...use something like BOOST_PP_SEQ_FOREACH instead of BOOST_PP_SEQ_TRANSFORM.
The Derived has bases classes generated from a sequence (SEQ). The bases classes themselves are instantiations of Base template type. I expected the code to be preprocessed into something like (just the important part):
struct Derived : Base< 1, 1 >, Base< 2, 2 >, Base< 3, 3 >, Base< 4, 4 > { }; but instead it is preprocessed into:
struct Derived : Base< 1, Base< 2, Base< 3, Base< 4 { }; This obviously is caused by Base being template with to parameters and thus having a comma.
Adding parenthesis around Base in OP solves the issue by generating expected code fully. But it still does not compile because parenthesis are not allowed in that place (base classes list).
Is there any other workaround? How to deal with it?
Hopefully that puts you on the right track. If you need more detail, holler back. - Jeff
I have following code: #include
#include template< int I, int J > struct Base { }; #define SEQ ( 1 ) ( 2 ) ( 3 ) ( 4 ) #define OP( s, data, elem ) Base< elem, elem > struct Derived : BOOST_PP_SEQ_ENUM( BOOST_PP_SEQ_TRANSFORM( OP, nil, SEQ ) ) { };
The Derived has bases classes generated from a sequence (SEQ). The bases classes themselves are instantiations of Base template type. I expected the code to be preprocessed into something like (just the important part): struct Derived : Base< 1, 1 >, Base< 2, 2 >, Base< 3, 3 >, Base< 4, 4 > { };
but instead it is preprocessed into: struct Derived : Base< 1, Base< 2, Base< 3, Base< 4 { };
This obviously is caused by Base being template with to parameters and thus having a comma. Adding parenthesis around Base in OP solves the issue by generating expected code fully. But it still does not compile because parenthesis are not allowed in that place (base classes list). Is there any other workaround? How to deal with it?
There are two ways you can solve this. The first is to use `BOOST_PP_SEQ_FOR_EACH_I`, like this, which is the simplest solution:
#define OP(r, data, i, x) BOOST_PP_COMMA_IF(i) Base
participants (3)
-
Adam Badura
-
Jeffrey Lee Hellrung, Jr.
-
paul Fultz