Boost logo

Boost :

From: Daniel Wallin (daniel_at_[hidden])
Date: 2007-06-05 15:52:48


Arkadiy Vertleyb wrote:
> "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:
[...]
>> 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.

Also, BOOST_PP_SEQ_FOR_EACH_I is independent from BOOST_PP_SEQ_FOR_EACH,
so if you only need two levels of nesting you can use both of them:

   #include <boost/preprocessor.hpp>

   #define INNER(R, DATA, I, ELEM)\
       **ELEM**,

   #define OUTER(R, DATA, ELEM)\
       << BOOST_PP_SEQ_FOR_EACH_I(INNER, ~, ELEM) >>,

   BOOST_PP_SEQ_FOR_EACH(OUTER, ~, ((1)(2)) ((3)(4)) )

gives the expected output. Otherwise you need to resort to either
flattening the structure first, or doing your own iteration.

HTH,

-- 
Daniel Wallin
Boost Consulting
www.boost-consulting.com

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