|
Boost Users : |
Subject: Re: [Boost-users] generate structs with all combinations of members from a given struct
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-02-07 10:03:44
> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of Larry Evans
> Sent: 06 February 2010 19:26
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] generate structs with all combinations of
> members from a given struct
>
> On 02/06/10 12:06, Hicham Mouline wrote:
> [snip]
> My *intuition* as well as posts from others (e.g. Joel Guzman and
> Eric Niebler) and a proto webpage:
>
> http://www.boost.org/doc/libs/1_41_0/doc/html/proto/appendices.html#boos
> t_proto.appendices.rationale
>
> suggests this PP method would be faster than the fusion-based solution.
>
> 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
};
all types are either int, unsigned int, long, double or bool.
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<S_field1_field5, M>
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(); };
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<appropriate_S, appropriate_M>& );
case 2: some_function(
multi_array_adapted_to_derive_from_base<appropriate_S, appropriate_M>& );
....
case 63: some_function(
multi_array_adapted_to_derive_from_base<appropriate_S, appropriate_M>& );
}
This is still work in progress.
Regards,
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