On 02/07/10 09:03, Hicham Mouline wrote:
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Larry Evans Sent: 06 February 2010 19:26 [snip]
However, I've been wondering how you would use this.
Starting from
struct S { type1 field1; ... typen fieldn; /// for now n=6 but may increase later }; [snip] The PP code generates all the structs like
struct S_field1_field5 { type1 field1; type5 field5; };
For each of these structs, we have the related type multi_array
an M-dimension array the elements of which are 1 of the generated structs. M can reach the order of 10, and the number of elements of the multi array can be quite large, therefore it is important to generate a multi_array that is as accurate as possible. The user selects at runtime which fields she is interested in, this then fills in a bitset<n>. At runtime we then select the multi_array we will work with.
I will find a way to adapt all of the multi_arrays to be derived from a multi_array_base via some wrapper. struct multi_array_base { virtual ~ multi_array_base(); };
Hmmm. What about multi_array_base being the S_empty: struct S_empty{}; IOW, this would be the 32nd version of S. Your PP method now generates 31 versions, you could just add the 32 version be S_empty. This makes sense because each time a field is added, it's like a derived class. IOW, S_empty would be the base class, and all other classes would be derived from it. I vaguely remember reading about that somewhere, IOW, that adding a field to a class is sorta like restricting the class is sorta like deriving from that class.
I have say 5 translation units tr1,tr2,tr3,tr4 and tr5.
The specific multi_array is generated in tr1. It needs to pass via tr2,tr3 and tr4 to reach tr5. tr2,3 and 4 do not need to know what exact multi_array type it is, so they just deal with multi_array_base. tr5 then dynamic casts the multi_array_base ref to the appropriate multi_array with the appropriate S.
pseudo_code tr1, itself geenrate switch( bitset.toulong() ) { case 1: some_function( multi_array_adapted_to_derive_from_base
& ); case 2: some_function( multi_array_adapted_to_derive_from_base & ); .... case 63: some_function( multi_array_adapted_to_derive_from_base & ); } This is still work in progress.
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. -regards, Larry