Boost logo

Boost Users :

Subject: [Boost-users] generate structs with all combinations of members from a given struct
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-01-30 01:37:52


Hello,

struct params {
  double field1;
  double field2;
  double field3;
  double fiedl4;
};

I would like to generate all the types that hold any combination of the members of params.

struct params_field1 {
  double field1;
};
struct params_field2 {
  double field2;
};
struct params_field3 {
  double field3;
};
struct params_field4 {
  double field4;
};
struct params_field1_field2 {
  double field1;
  double field2;
};
struct params_field1_field3 {
  double field1;
  double field3;
};
struct params_field1_field4 {
  double field1;
  double field4;
};
struct params_field2_field3 {
  double field2;
  double field3;
};
struct params_field2_field4 {
  double field2;
  double field4;
};
struct params_field3_field4 {
  double field3;
  double field4;
};
struct params_field1_field2_field3 {
  double field1;
  double field2;
  double field3;
};
struct params_field1_field2_field4 {
  double field1;
  double field2;
  double field4;
};
struct params_field1_field3_field4 {
  double field1;
  double field3;
  double field4;
};
struct params_field2_field3_field4 {
  double field2;
  double field3;
  double field4;
};
struct params_field1_field2_field3_field4 {
  double field1;
  double field2;
  double field3;
  double field4;
};

There are 15 of these, which is 2^4 -1, where 4 is the number of members in params.

Assuming params is adapted as a fusion sequence, this looks doable with PP?
Should I be looking at BOOST_PP_LIST_FOLD_xxx macros?

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