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-02-14 15:02:50


On 02/09/10 16:12, Hicham Mouline wrote:
>> -----Original Message-----
>> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
>> bounces_at_[hidden]] On Behalf Of Larry Evans
>> Sent: 09 February 2010 18:11
>> To: boost-users_at_[hidden]
>> Subject: Re: [Boost-users] generate structs with all combinations of
>> members from a given struct
[snip]
>> I'd be interesting in seeing this code when you're done with it.
>> I'd like to try using:
>>
>> composite_tagged_seq
>> < all_of_aligned
>> , field_I1
>> , field_I2
>> ...
>> , field_In
>> >
>>
>> where field_I1...field_In is some subset of S::field1,...field5
>> and composite_tagged is from composite_tagged_seq.zip in the
>> boost vault:
>>
>> http://www.boostpro.com/vault/index.php?&directory=Data Structures
>>
>> Then compare the compile-time and run-time performance. I've no
>> doubt it would be slower than the PP version, but I'm just
>> curious about how much.

The attached shows a test driver using composite_tagged_seq.
The composite_tagged_seq used is a bit different than the one in
vault. The one used modified layout to handle the case
where the type was void. In this case, not project template
function for a void member is produced.

The fields_subsets_t time contains 32 members, 1 for each
subset of 5 fields. However, as shown in the driver,
you have to access the field with:

   field_subset_struct.project<FieldNum>();

The compile time was slow (maybe 10-20 secs) on my machine,
but that sounds a lot faster than you PP method.

If you think you can use this, I'll upload the code to
the sandbox.

-regards,
Larry

BTW, the output is:

/home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_4v/sandbox/variadic_templates/libs/mpl/sandbox/composite_tagged~field_subsets~cross_product_pack.exe

absent_fields_seq=
package< absent_tag, type=1>
package< absent_tag, type=2>
package< absent_tag, type=3>
package< absent_tag, type=4>
package< absent_tag, type=5>
size<select_fields_seq>::value=32
select_fields_seq=
{ absent , absent , absent , absent , absent }
{ absent , absent , absent , absent , ( type= 5) }
{ absent , absent , absent , ( type= 4) , absent }
{ absent , absent , absent , ( type= 4) , ( type= 5) }
{ absent , absent , ( type= 3) , absent , absent }
{ absent , absent , ( type= 3) , absent , ( type= 5) }
{ absent , absent , ( type= 3) , ( type= 4) , absent }
{ absent , absent , ( type= 3) , ( type= 4) , ( type= 5) }
{ absent , ( type= 2) , absent , absent , absent }
{ absent , ( type= 2) , absent , absent , ( type= 5) }
{ absent , ( type= 2) , absent , ( type= 4) , absent }
{ absent , ( type= 2) , absent , ( type= 4) , ( type= 5) }
{ absent , ( type= 2) , ( type= 3) , absent , absent }
{ absent , ( type= 2) , ( type= 3) , absent , ( type= 5) }
{ absent , ( type= 2) , ( type= 3) , ( type= 4) , absent }
{ absent , ( type= 2) , ( type= 3) , ( type= 4) , ( type= 5) }
{ ( type= 1) , absent , absent , absent , absent }
{ ( type= 1) , absent , absent , absent , ( type= 5) }
{ ( type= 1) , absent , absent , ( type= 4) , absent }
{ ( type= 1) , absent , absent , ( type= 4) , ( type= 5) }
{ ( type= 1) , absent , ( type= 3) , absent , absent }
{ ( type= 1) , absent , ( type= 3) , absent , ( type= 5) }
{ ( type= 1) , absent , ( type= 3) , ( type= 4) , absent }
{ ( type= 1) , absent , ( type= 3) , ( type= 4) , ( type= 5) }
{ ( type= 1) , ( type= 2) , absent , absent , absent }
{ ( type= 1) , ( type= 2) , absent , absent , ( type= 5) }
{ ( type= 1) , ( type= 2) , absent , ( type= 4) , absent }
{ ( type= 1) , ( type= 2) , absent , ( type= 4) , ( type= 5) }
{ ( type= 1) , ( type= 2) , ( type= 3) , absent , absent }
{ ( type= 1) , ( type= 2) , ( type= 3) , absent , ( type= 5) }
{ ( type= 1) , ( type= 2) , ( type= 3) , ( type= 4) , absent }
{ ( type= 1) , ( type= 2) , ( type= 3) , ( type= 4) , ( type= 5) }
no_f1_v.F_2=field_type=2
no_f1_v.F_3=field_type=3

Compilation finished at Sun Feb 14 13:59:27




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