[preprocessor] having trouble using reentrant macros
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)
For me this keeps producing rubbish with a lot of non-expanded macro
names embedded.
I've reduced this down to a minimal example iterating over a
2-dimensional sequence; I know the final line isn't valid C++, I'm
just checking preprocessing results at this stage.
#include
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.
Unfortunately, it isn't realistic to implement everything in a reentrant
way (i.e. explosion of # of macros).
With Chaos--which requires a really good preprocessor (such as gcc)--
rather than the Boost.Preprocessor), all higher-order algorithms are
reentrant. E.g.
// 1.cpp
#include
On 29 March 2012 16:29, Paul Mensonides
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.
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
On Mon, 02 Apr 2012 13:23:02 +0100, Rob Desbois wrote:
On 29 March 2012 16:29, Paul Mensonides
wrote:
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".
http://sourceforge.net/projects/chaos-pp The code is in CVS. There is no packaged release though it is stable. The best documentation index is probably the headers.html file in the built-docs folder. Regards, Paul Mensonides
on Mon Apr 02 2012, Paul Mensonides
On Mon, 02 Apr 2012 13:23:02 +0100, Rob Desbois wrote:
On 29 March 2012 16:29, Paul Mensonides
wrote: 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".
http://sourceforge.net/projects/chaos-pp
The code is in CVS. There is no packaged release though it is stable. The best documentation index is probably the headers.html file in the built-docs folder.
Paul, how are compilers doing these days? Is the use of Chaos reasonably portable in practice to recent compilers, or are the preprocessors still too badly broken? Thanks, -- Dave Abrahams BoostPro Computing http://www.boostpro.com
On Wed, 04 Apr 2012 21:10:10 -0400, Dave Abrahams wrote:
Paul, how are compilers doing these days? Is the use of Chaos reasonably portable in practice to recent compilers, or are the preprocessors still too badly broken?
I don't regularly use any of them except GCC (which is good), so I can't say for sure. However, VC is as bad as always, and since that's a pretty "important" compiler for portable code... Regards, Paul Mensonides
on Thu Apr 05 2012, Paul Mensonides
On Wed, 04 Apr 2012 21:10:10 -0400, Dave Abrahams wrote:
Paul, how are compilers doing these days? Is the use of Chaos reasonably portable in practice to recent compilers, or are the preprocessors still too badly broken?
I don't regularly use any of them except GCC (which is good), so I can't say for sure. However, VC is as bad as always, and since that's a pretty "important" compiler for portable code...
<fumes> Bah! What's it going to take to get those guys to fix their preprocessor?! </fumes> -- Dave Abrahams BoostPro Computing http://www.boostpro.com
On 4/5/2012 10:50 AM, Dave Abrahams wrote:
on Thu Apr 05 2012, Paul Mensonides
wrote: On Wed, 04 Apr 2012 21:10:10 -0400, Dave Abrahams wrote:
Paul, how are compilers doing these days? Is the use of Chaos reasonably portable in practice to recent compilers, or are the preprocessors still too badly broken?
I don't regularly use any of them except GCC (which is good), so I can't say for sure. However, VC is as bad as always, and since that's a pretty "important" compiler for portable code...
<fumes> Bah! What's it going to take to get those guys to fix their preprocessor?! </fumes>
<rant> When one submits an obvious bug on the Microsoft bug reporting page regarding their C++ preprocessor their answer is an almost immediate "won't fix". If Stan Lippman and/or Herb Sutter are still involved in the Microsoft C++ development team, and they can personally be approached by C++ programmers who know them regarding the VC++ preprocessor, I believe it would do much more good in fixing the VC++ preprocessor than all the bug reports to Microsoft ever will. </rant>
On Thu, Mar 29, 2012 at 6:39 AM, Rob Desbois
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)
[...] 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. - Jeff
participants (5)
-
Dave Abrahams
-
Edward Diener
-
Jeffrey Lee Hellrung, Jr.
-
Paul Mensonides
-
Rob Desbois