On 01/30/10 00:37, Hicham Mouline wrote:
Hello,
struct params { double field1; double field2; double field3; double fiedl4; };
I would like to generate all the types that hold any combination of the members of params.
struct params_field1 { double field1; }; struct params_field2 { double field2; }; struct params_field3 { double field3; }; struct params_field4 { double field4; }; struct params_field1_field2 { double field1; double field2; }; struct params_field1_field3 { double field1; double field3; }; struct params_field1_field4 { double field1; double field4; }; struct params_field2_field3 { double field2; double field3; }; struct params_field2_field4 { double field2; double field4; }; struct params_field3_field4 { double field3; double field4; }; struct params_field1_field2_field3 { double field1; double field2; double field3; }; struct params_field1_field2_field4 { double field1; double field2; double field4; }; struct params_field1_field3_field4 { double field1; double field3; double field4; }; struct params_field2_field3_field4 { double field2; double field3; double field4; }; struct params_field1_field2_field3_field4 { double field1; double field2; double field3; double field4; };
There are 15 of these, which is 2^4 -1, where 4 is the number of members in params.
Assuming params is adapted as a fusion sequence, this looks doable with PP? Should I be looking at BOOST_PP_LIST_FOLD_xxx macros?
I think the following might work: step1: create sequence of fields: seq=(field1,field2,...,fieldn) step2: create a sequence of a sequence of fields by fold with pop_back: seq_fold= ( (field1,field2,....,fieldn) , (field1,field2,...,fieldn-1) ... , (field1) ) step3 form the cross product of seq_fold using code posted here: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?CPPTM_Answers... or, if using variadic templates compiler is OK for you, in list_comprehension.cpp here: http://www.boostpro.com/vault/index.php?&directory=variadic_templates WARNING. I haven't tried this at all. but it seems it should work. HTH. -Larry