|
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-06 14:26:19
On 02/06/10 12:06, Hicham Mouline wrote:
[snip]
> 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; };
>
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#boost_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. I suspect it's
related to spirit's permutation:
m1_tok ^ m2_tok ^ m3_tok
where, using the notation from:
m1_tok:int, m2_tok:double, m3_tok:double
--> (m1_tok^m2_tok^m3_tok):params_subset
where:
typedef
tuple
< optional<int> //corresponding to S::m1
, optional<double>//corresponding to S::m2
, optional<double>//corresponding to S::m3
>
params_subset;
and maybe you were planning on somehow converting the
params_subset attribute to one of the structures generated
by TRUCT_MEMBERS_COMBINATIONS_SEQ(struct_members_seq).
Is that your aim?
>
> Questions:
Sorry, I don't know enough to answer any of these questions :(.
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