Boost logo

Boost :

Subject: Re: [boost] [preprocessor] nested for_each not working like expected
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2013-08-07 14:58:38


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

I find this annoying from time to time as well.

Regards,
Nate

[1] http://www.boost.org/doc/libs/1_54_0/libs/preprocessor/doc/
                                               


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