Boost logo

Boost Users :

Subject: Re: [Boost-users] [preprocessor] having trouble using reentrant macros
From: Rob Desbois (rob.desbois_at_[hidden])
Date: 2012-04-02 08:23:02


On 29 March 2012 16:29, Paul Mensonides <pmenso57_at_[hidden]> wrote:
> On Thu, 29 Mar 2012 14:39:20 +0100, Rob Desbois wrote:
>
>> I'm unable to use the reentrant macros for iteration currently..I think
>> I'm probably misunderstanding their usage, and a push in the right
>> direction would be much appreciated.
>>
>> My need is to iterate through a sequence, then iterate through a
>> sequence nested within each element.
>> As I understand, I should be able to call (e.g.): *
>> BOOST_PP_SEQ_FOR_EACH(OP, data, seq) to iterate through the outer
>> sequence * then in OP(r, data, elem) call BOOST_PP_SEQ_FOR_EACH_R(r,
>> OP2, data, elem)
>
> Neither BOOST_PP_SEQ_FOR_EACH nor BOOST_PP_SEQ_TRANSFORM are reentrant
> algorithms.  In fact, only a relative few of the core algorithms in the pp-
> lib are reentrant.  In the cases of SEQ_FOR_EACH and SEQ_TRANSFORM, the
> SEQ_FOR_EACH_R and SEQ_TRANSFORM_S variants of those macros reenter
> BOOST_PP_FOR and BOOST_PP_SEQ_FOLD_LEFT efficiently.  They do not reenter
> SEQ_FOR_EACH and SEQ_TRANSFORM.

Aha, thanks for that - I'd misunderstood that some of the _R functions
and friends were solely for efficiency, and didn't imply reentrancy.
FWIW that's not immediately obvious from the docs, at least to someone
only just becoming familiar with Boost PP.
Having read a related thread from some time back I appreciate that you
don't wish to add loads of redundancy to the docs, but if there were a
simple warning that "this function is not reentrant" on the pages for
the relevant loop functions, that would highlight this pitfall. Just
my penny's worth.

> With Chaos--which requires a really good preprocessor (such as gcc)--
> rather than the Boost.Preprocessor), all higher-order algorithms are
> reentrant.  E.g.

Thanks very much for the example code - looks good.
FYI I couldn't access the Website http://chaos-pp.sourceforge.net/
linked from the sourceforge page; I just get an empty page titled
"BLANK".

On 29 March 2012 17:26, Jeffrey Lee Hellrung, Jr.
<jeffrey.hellrung_at_[hidden]> wrote:
> Just to add to Paul's reply, no, this isn't going to work, as you've
> discovered, due to your attempt to expand SEQ_FOR_EACH_R within an expansion
> of SEQ_FOR_EACH_R. I ran into this inconvenience at some point, too, and
> simply wrote up a script to define a collection of macros similar to
> SEQ_FOR_EACH and SEQ_TRANSFORM that were reentrant (so they used
> token-pasting with an pp integral constant). It's fun exercise, but if
> you're not into writing it yourself, I'd be happy to point you to the code.

Thanks Jeffrey - I did think of doing something like what you've
suggested, despite baulking slightly at the prospect! Instead though
I've modified my approach so that I have removed the need for
reentrancy in the macros I'm using. Many thanks for the offer anyway.

--rob


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net