PP: how to use automatic recursion

Hello,
I am trying to generate many types from 1 struct (for full background, please see thread "generate structs with all combinations of members from a given struct"), with the help of Boost.PP
#include

AMDG Hicham Mouline wrote:
I am trying to generate many types from 1 struct (for full background, please see thread "generate structs with all combinations of members from a given struct"), with the help of Boost.PP
#include
#include #include #include #include #include #include #define STRUCTMEMBERS ((double,m1))((double,m2))((double,m3))((double,m4))((double,m5))
#define SEQ_LAST_ELEM(seq) \ BOOST_PP_SEQ_ELEM( BOOST_PP_SUB(BOOST_PP_SEQ_SIZE(seq), 1), seq)
#define UPDATE_MAIN_SEQ(mainseq, globalseq)\ BOOST_PP_IF( BOOST_PP_SEQ_SIZE(mainseq),\ BOOST_PP_SEQ_PUSH_BACK(\ mainseq,\ ((SEQ_LAST_ELEM(mainseq))(BOOST_PP_SEQ_HEAD(globalseq)))\ ),\ ((BOOST_PP_SEQ_HEAD(globalseq)))\ )
#define COMBINATIONS(seq, combseq)\ BOOST_PP_IF( BOOST_PP_SEQ_SIZE(seq),\ COMBINATIONS( UPDATE_MAIN_SEQ(combseq,seq), BOOST_PP_SEQ_POP_FRONT(seq) ), \ combseq\ )
#define COMBOS COMBINATIONS(STRUCTMEMBERS, BOOST_PP_SEQ_NIL)
COMBOS
Reading PP docs, I just realized that the preprocessor disallows recursion ( the COMBINATIONS macro calls itself in my case), but I didn't understand the reentrancy topic page.
How can I change the above code to make the recursive COMBINATIONS possible?
Look at http://sourceforge.net/projects/chaos-pp/. I believe that it has a mechanism to support recursion. In Christ, Steven Watanabe

On 1 February 2010 07:27, Hicham Mouline
I am trying to generate many types from 1 struct (for full background, please see thread "generate structs with all combinations of members from a given struct"), with the help of Boost.PP
Recursion is tricky, you're generally better of using the looping macros supplied by the preprocessor library. Did you see the macros in my previous email? http://lists.boost.org/boost-users/2010/01/55739.php Daniel
participants (3)
-
Daniel James
-
Hicham Mouline
-
Steven Watanabe