Boost logo

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-06 13:06:53


> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of Larry Evans
> Sent: 31 January 2010 18:04
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] generate structs with all combinations of
> members from a given struct
>
> [snip]
>
> >> Because all the members of params are double, there is no way to
> >> differentiate between different the 1st and 2nd vector<double>
> >
> > Yes; however, Couldn't you, pair each type with it's index?
> > IOW, you have, instead of:
> >
> > typedef
> > package_c<int,9001,9002,9003>::pkg_type
> > fields_t
> > ;
> >

Larry,

I have finally reached a Boost.PP based solution which I describe below. I
will then go back to your fusion-based solution.
My point is to compare compile-time, memory requirement of the compiler and
ease of use of the generated types.

Here is my solution (the attached files compiles and preprocesses at least
under g++4.4 with: g++ -E -c structcombos.cpp).

With

   struct S {
      int m1;
      double m2;
      double m3;
   };

the user is required to define the macro

#define struct_members_seq ((int,m1))((double,m2))((double,m3))

then calls the macro

STRUCT_MEMBERS_COMBINATIONS_SEQ(struct_members_seq)

This expands to
struct params_m3 { double m3; }; struct params_m2 { double m2; }; struct
params_m2_m3 { double m2; double m3; }; struct params_m1 { int m1; }; struct
params_m1_m3 { int m1; double m3; }; struct params_m1_m2 { int m1; double
m2; }; struct params_m1_m2_m3 { int m1; double m2; double m3; };

Questions:
1. It takes a little while to preprocess. Are there optimizations that are
visible in the attached file?
2. How do I obtain some vertical appearance that is easier to read? Can I
generate the newline somehow?

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