
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