Boost logo

Boost Users :

Subject: Re: [Boost-users] generate structs with all combinations of members from a given struct
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-01-30 19:24:11


On 01/30/10 13:35, Larry Evans wrote:
> 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.
> [snip]
>
> Step1:
> Create cross-product of void and {field1,field2,...}.
> This will produce a sequence of pairs:
>
> no_yes =
> ( (void,field1)
> , (void,field2)
> ...
> , (void,fieldn)
> )
>
> Step2:
>
> Create the crosss product of all rows in no_yes.
>
> cross_no_yes =
> ( (void,void,..void)
> , (field1,void,...void)
> , (void,field2,void...,void)
> ...
> , (field1,field2,...fieldn)
> )
>
> step3:
>
> remove all the voids in all the rows of cross_no_yes.
>
> Since the size<no_yes> == n and each element in that row is size 2,
> the cross_no_yes size would be 2^n. Then simply rm the all void row.
>
> Not tested.
Now tested. The attached produces:

/home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_4v/sandbox/variadic_templates/libs/mpl/sandbox/list_comprehension~subsets.exe

absent_fields_seq=
( Absent=9000, Field=9001)
( Absent=9000, Field=9002)
( Absent=9000, Field=9003)
size<select_fields_seq>::value=8
select_fields_seq=
{ 9000, 9000, 9000}
{ 9000, 9000, 9003}
{ 9000, 9002, 9000}
{ 9000, 9002, 9003}
{ 9001, 9000, 9000}
{ 9001, 9000, 9003}
{ 9001, 9002, 9000}
{ 9001, 9002, 9003}

Compilation finished at Sat Jan 30 18:17:41

9000 indicates absence of a field. 900I, for I>0,
indicates presence of the I-th field.

HTH.

-regards,
Larry




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net