Boost logo

Boost :

Subject: Re: [boost] [preprocessor] nested for_each not working like expected
From: Eric Niebler (eniebler_at_[hidden])
Date: 2013-08-07 15:48:48


On 13-08-07 11:58 AM, Nathan Ridge wrote:
>> I can't figure out what I'm doing wrong. According to the docs, this
>> should work:
>>
>> #define S0 (0)(1)(2)(3)
>> #define S1 (5)(6)(7)(8)
>> #define M4(R, DATA, ELEM) (DATA,ELEM)
>> #define M2(R, DATA, ELEM) BOOST_PP_SEQ_FOR_EACH_R(R, M4, ELEM, S1);
>> BOOST_PP_SEQ_FOR_EACH(M2, ~, S0)
>>
>> I expect to get a sequence like (0,1)(0,2)... for each combination. I
>> get gibberish. (Please don't tell me to use FOR_EACH_PRODUCT. In my real
>> use case, M2 and M4 are far more complicated, and a simple product won't
>> do.)
>>
>> Can anybody please tell me what I'm doing wrong? TIA,
>
> According to [1], only BOOST_PP_FOR, BOOST_PP_WHILE, and BOOST_PP_REPEAT
> are reentrant. Other looping macros, like SEQ_FOR_EACH, are not.

Yes, but [2] indicates that SEQ_FOR_EACH is implemented in terms of FOR
and has a _R version for reentry. Why is it provided if it doesn't work?

[2]
http://www.boost.org/doc/libs/1_54_0/libs/preprocessor/doc/ref/seq_for_each_r.html

-- 
Eric Niebler
Boost.org

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