Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2007-06-05 15:24:38


"Eric Niebler" <eric_at_[hidden]> wrote
>I must be doing something stupid. How can I process a sequence of
> sequences? I expected to be able to use nested invocations of
> SEQ_FOR_EACH, but I'm not getting the results I expect. Here's my code:
>
> #include <boost/preprocessor.hpp>
>
> #define INNER(R, DATA, ELEM)\
> **ELEM**,
>
> #define OUTER(R, DATA, ELEM)\
> << BOOST_PP_SEQ_FOR_EACH_R(R, INNER, ~, ELEM) >>,
>
> BOOST_PP_SEQ_FOR_EACH(OUTER, ~, ((1)(2)) ((3)(4)) )
>
> I expected something like:
> << **1**, **2**, >>, << **3**, **4**, >>,
>
> But instead I'm getting:
> << BOOST_PP_SEQ_FOR_EACH_M(3, (INNER, ~, (1)(2) (nil)))
> BOOST_PP_SEQ_FOR_EACH_M(4, (INNER, ~, (2) (nil))) >>, <<
> BOOST_PP_SEQ_FOR_EACH_M(4, (INNER, ~, (3)(4) (nil)))
> BOOST_PP_SEQ_FOR_EACH_M(5, (INNER, ~, (4) (nil))) >>,
>
> I've tried both msvc-8.0 and gcc-3.4. Can anybody see my mistake?

Unfortunately not every macro can be nested. IIUC, by default the
preprocessor does not allow it. For some of macros special code is
implemented inside Boost PP to allow nesting. If you use BOOST_PP_REPEAT,
for instance, you should not have any problems.

Regards,
Arkadiy


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk