[pre-processor ] help needed

Hello *, I have some pre-processor sequence in form of: (X1) (X2) (X3) (X4) which is expanded by BOOST_PP_SEQ_FOR_EACH to template parameters: some_template<X1, X2, X3, X4> ... My problem now is that some of Xn parameters can be a template instantiation and that actually causes PP to think, that there are more parameters to the function applied by ..._SEQ_FOR_EACH. Example: some_other_template<T1, T2> cause preprocessor to think that there are 2 params some_other_template<T1 and T2>. Putting the parameter into additional braces like ((X4)) results in the template: some_template<X1, X2, X3, (X4)> and that results in a compiler error. I know this construct can switch off ADL, but I don't know why it result here in a compiler error, since I fully qualify the X4 (from which namespace it is). Is there any way to treat Xn as a single paramer but during the final pre-processing stage get rid of additional braces? Many thanks, Ovanes

AMDG Ovanes Markarian wrote:
Hello *,
I have some pre-processor sequence in form of:
(X1) (X2) (X3) (X4)
which is expanded by BOOST_PP_SEQ_FOR_EACH to template parameters:
some_template<X1, X2, X3, X4> ...
My problem now is that some of Xn parameters can be a template instantiation and that actually causes PP to think, that there are more parameters to the function applied by ..._SEQ_FOR_EACH. Example: some_other_template<T1, T2> cause preprocessor to think that there are 2 params some_other_template<T1 and T2>.
Putting the parameter into additional braces like ((X4)) results in the template:
some_template<X1, X2, X3, (X4)> and that results in a compiler error. I know this construct can switch off ADL, but I don't know why it result here in a compiler error, since I fully qualify the X4 (from which namespace it is). Is there any way to treat Xn as a single paramer but during the final pre-processing stage get rid of additional braces?
There are a couple of ways to do it. You can make each element of the Seq to be itself a seq and then call BOOST_PP_SEQ_ENUM on the inside: ((X1)) ((X2)) ((some_other_template<T1)(T2>)) Another way is to use template metaprogramming (X1)(X2)(parenthesize_type(wrap<some_other_template<T1, T2>>)) template<class T> struct unparenthesize { typedef T type; }; template<class T> struct unparenthesize<parenthesized_type(wrap<T>)> { typedef T type; }; In Christ, Steven Watanabe

Steven, thanks a lot for your answers. That could help, but I would like to have some simple interface for the user. I don't want users write a lot of template classes where they would not really understand the background. In the current approach X4 is the trait type: Asking the users to write: (X1)(X2)(X3)((traitX<T1)(T2>)) is not a great idea. As well as: (X1)(X2)(X3)(paranthesized_type(wrap<traitX<T1, T2> >)) I could try doing it in the background and still ask users write: (X1)(X2)(X3)((traitX<T1,T2>)) I just thought there could be a simpler way of doing it. Many thanks for your help, Ovanes On Jan 28, 2008 7:12 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Ovanes Markarian wrote:
Hello *,
I have some pre-processor sequence in form of:
(X1) (X2) (X3) (X4)
which is expanded by BOOST_PP_SEQ_FOR_EACH to template parameters:
some_template<X1, X2, X3, X4> ...
My problem now is that some of Xn parameters can be a template instantiation and that actually causes PP to think, that there are more parameters to the function applied by ..._SEQ_FOR_EACH. Example: some_other_template<T1, T2> cause preprocessor to think that there are 2 params some_other_template<T1 and T2>.
Putting the parameter into additional braces like ((X4)) results in the template:
some_template<X1, X2, X3, (X4)> and that results in a compiler error. I know this construct can switch off ADL, but I don't know why it result here in a compiler error, since I fully qualify the X4 (from which namespace it is). Is there any way to treat Xn as a single paramer but during the final pre-processing stage get rid of additional braces?
There are a couple of ways to do it. You can make each element of the Seq to be itself a seq and then call BOOST_PP_SEQ_ENUM on the inside:
((X1)) ((X2)) ((some_other_template<T1)(T2>))
Another way is to use template metaprogramming
(X1)(X2)(parenthesize_type(wrap<some_other_template<T1, T2>>))
template<class T> struct unparenthesize { typedef T type; };
template<class T> struct unparenthesize<parenthesized_type(wrap<T>)> { typedef T type; };
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Steven, one additional question. In the second solution paranthesized_type is a function type, which is passed to the temple? If so, then I need to declare somewhere an overload. Isn't it so? Thanks, Ovanes There are a couple of ways to do it. You can make each element of the
Seq to be itself a seq and then call BOOST_PP_SEQ_ENUM on the inside:
((X1)) ((X2)) ((some_other_template<T1)(T2>))
Another way is to use template metaprogramming
(X1)(X2)(parenthesize_type(wrap<some_other_template<T1, T2>>))
template<class T> struct unparenthesize { typedef T type; };
template<class T> struct unparenthesize<parenthesized_type(wrap<T>)> { typedef T type; };
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Oh, I got it... Sorry again for bothering. paranthesized_type is a type and the construct paranthesized_type (SomeParam) is the function type which expects a function, which returns paranthesized_type and receives SomeParam as input parameter. Steven this is a great idea! Many thanks! This solution will defenetely help me solving my problem! Ovanes On Jan 29, 2008 10:24 AM, Ovanes Markarian <om_boost@keywallet.com> wrote:
Steven,
one additional question. In the second solution
paranthesized_type is a function type, which is passed to the temple? If so, then I need to declare somewhere an overload. Isn't it so?
Thanks, Ovanes
There are a couple of ways to do it. You can make each element of the
Seq to be itself a seq and then call BOOST_PP_SEQ_ENUM on the inside:
((X1)) ((X2)) ((some_other_template<T1)(T2>))
Another way is to use template metaprogramming
(X1)(X2)(parenthesize_type(wrap<some_other_template<T1, T2>>))
template<class T> struct unparenthesize { typedef T type; };
template<class T> struct unparenthesize<parenthesized_type(wrap<T>)> { typedef T type; };
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Ovanes Markarian
-
Steven Watanabe