Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-06-05 15:44:58


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:
>>
>> #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.

That cannot be the answer. The sole reason that BOOST_PP_SEQ_FOR_EACH_R
(note the trailing _R) exists is so that it can be reentered, IIUC. Is
this a bug?

-- 
Eric Niebler
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