Boost logo

Boost Users :

Subject: [Boost-users] [preprocessor] having trouble using reentrant macros
From: Rob Desbois (rob.desbois_at_[hidden])
Date: 2012-03-29 09:39:20

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 <boost/preprocessor/seq/transform.hpp>

    #define INNER(s, data, elem) <elem>
    #define MIDDLE(s, data, seq) BOOST_PP_SEQ_TRANSFORM_S(s, INNER, data, seq)
    #define OUTER(seqseq) BOOST_PP_SEQ_TRANSFORM( MIDDLE, _, seqseq)

    outer gives: OUTER( ((a) (b) (c)) ((i) (j) (k)) ((x) (y) (z)) )

Resultant output of this, with preprocessor line directives and empty
lines removed, is:
   outer gives: (
             , _, (nil)), a), b), c)) (
             , _, (nil)), i), j), k)) (
             , _, (nil)), x), y), z))

For reference, I am using the following:
   boost 1.46.00
   g++ (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)

TIA --rob

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at