Subject: Re: [boost] [preprocessor] nested for_each not working like expected
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2013-08-07 16:01:41
> >> 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 , only BOOST_PP_FOR, BOOST_PP_WHILE, and BOOST_PP_REPEAT
> > are reentrant. Other looping macros, like SEQ_FOR_EACH, are not.
> Yes, but  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?
My understanding is that SEQ_FOR_EACH is reentrant with FOR, but not with itself.
So one of the inner and outer loops can use SEQ_FOR_EACH, and the other FOR, and
this works fine despite the fact that SEQ_FOR_EACH is implemented in terms of for.
However they cannot both use SEQ_FOR_EACH.
Also, I believe the _R versions are for efficiency only - that, is, the make re-entrancy
more efficient in cases where it would already be possible, just less efficient, without
I'm not certain about this, though. Perhaps Paul or Edward can clarify these points.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk