On 6 February 2010 19:42, Hicham Mouline wrote:
Attached now,
The code I posted for getting the subsets before should be faster,
here it is adapted for sequences:
#include
/////////////////////////////////////////////////////////////////////
// Generates the non-empty subsets of a sequence
#define SUBSETS(values) \
SUBSETS2(BOOST_PP_SEQ_SIZE(values), \
BOOST_PP_SEQ_TO_TUPLE(values))
#define SUBSETS2(size, values) \
BOOST_PP_CAT(SUBSETS_, size) values
#define SUBSETS_1(a1) ((a1))
#define SUBSETS_2(a1,a2) \
SUBSETS_COMBINE(a2, SUBSETS_1(a1))
#define SUBSETS_3(a1,a2,a3) \
SUBSETS_COMBINE(a3, SUBSETS_2(a1,a2))
#define SUBSETS_4(a1,a2,a3,a4) \
SUBSETS_COMBINE(a4, SUBSETS_3(a1,a2,a3))
#define SUBSETS_5(a1,a2,a3,a4,a5) \
SUBSETS_COMBINE(a5, SUBSETS_4(a1,a2,a3,a4))
#define SUBSETS_6(a1,a2,a3,a4,a5,a6) \
SUBSETS_COMBINE(a6, SUBSETS_5(a1,a2,a3,a4,a5))
#define SUBSETS_7(a1,a2,a3,a4,a5,a6,a7) \
SUBSETS_COMBINE(a7, SUBSETS_6(a1,a2,a3,a4,a5,a6))
#define SUBSETS_8(a1,a2,a3,a4,a5,a6,a7,a8) \
SUBSETS_COMBINE(a8, SUBSETS_7(a1,a2,a3,a4,a5,a6,a7))
#define SUBSETS_COMBINE(x, seq_seq) \
seq_seq \
((x)) \
BOOST_PP_SEQ_FOR_EACH(SUBSETS_COMBINE_IMPL, x, seq_seq)
#define SUBSETS_COMBINE_IMPL(r, elem, seq) \
(seq (elem))
/////////////////////////////////////////////////////////////////////
// Example of use:
SUBSETS(
((char, field1))
((float, field2))
((std::string, field3))
((int, field4))
)