#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define STRUCT_MEMBERS_SEQ ((int,m1))((double,m2))((double,m3)) // #define PRED(r,state) BOOST_PP_TUPLE_ELEM(2, 1, state) // #define OP(r,state) (BOOST_PP_MUL(BOOST_PP_TUPLE_ELEM(2, 0, state), 2), BOOST_PP_SUB(BOOST_PP_TUPLE_ELEM(2, 1, state), 1)) // #define MACRO(r,state) (state) // #define POWERSEQ(x) BOOST_PP_FOR((2,x), PRED, OP, MACRO) // #define LAST_TUPLE(x) BOOST_PP_SEQ_ELEM(BOOST_PP_SUB(BOOST_PP_SEQ_SIZE(POWERSEQ(x)),1), POWERSEQ(x)) // #define POWER2(x) BOOST_PP_TUPLE_ELEM(2, 0, LAST_TUPLE(x)) #define POWER2_0 1 #define POWER2_1 2 #define POWER2_2 4 #define POWER2_3 8 #define POWER2_4 16 #define POWER2_5 32 #define POWER2_6 64 #define POWER2_7 128 #define POWER2_8 256 #define POWER2_9 512 #define POWER2_10 1024 #define POWER2(x) BOOST_PP_CAT(POWER2_,x) /// /// For x=5, generates a sequence from 1 to 2^5-1=31 ///((1,5)) ((2, 5)) ((3, 5)) ((4, 5)) ((5, 5)) ((6, 5)) ((7, 5)) ((8, 5)) ((9, 5)) ((10, 5)) ((11, 5)) ((12, 5)) ((13, 5)) ((14, 5)) ((15, 5)) ((16, 5)) ((17, 5)) ((18, 5)) ((19, 5)) ((20, 5)) ((21, 5)) ((22, 5)) ((23, 5)) ((24, 5)) ((25, 5)) ((26, 5)) ((27, 5)) ((28, 5)) ((29, 5)) ((30, 5)) ((31, 5)) #define FROM_1_TO_2_POWER_x_MINUS_1_PRED(r, state) BOOST_PP_SUB(POWER2(BOOST_PP_TUPLE_ELEM(2, 1, state)), BOOST_PP_TUPLE_ELEM(2, 0, state)) #define FROM_1_TO_2_POWER_x_MINUS_1_OP(r,state) (BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(2, 0, state),1), BOOST_PP_TUPLE_ELEM(2, 1, state)) #define FROM_1_TO_2_POWER_x_MINUS_1_MACRO(r,state) (state) #define FROM_1_TO_2_POWER_x_MINUS_1(x) BOOST_PP_FOR((1,x),FROM_1_TO_2_POWER_x_MINUS_1_PRED, FROM_1_TO_2_POWER_x_MINUS_1_OP, FROM_1_TO_2_POWER_x_MINUS_1_MACRO) /// /// Calculates the binary representation of a number x with y being the unreachable sup of representable numbers /// The algorithm uses BOOST_PP_FOR and the result is available in the last iteration /// The expansion BINARY_REPR_SEQ(17, 32) generates: ///((17, 32,BOOST_PP_SEQ_NIL)) (( 17, 16, (1) )) (( 1, 8, (1)(0) )) (( 1, 4, (1)(0)(0) )) (( 1, 2, (1)(0)(0)(0) )) (( 1, 1, (1)(0)(0)(0)(1) )) /// #define BINARY_REPR_SEQ_PRED(r,state) BOOST_PP_TUPLE_ELEM(3, 1, state) #define BINARY_REPR_SEQ_OP(r,state) ( BOOST_PP_MOD(\ BOOST_PP_TUPLE_ELEM(3, 0, state),\ BOOST_PP_TUPLE_ELEM(3, 1, state)\ ),\ BOOST_PP_DIV(BOOST_PP_TUPLE_ELEM(3, 1, state),2), \ BOOST_PP_SEQ_PUSH_BACK(\ BOOST_PP_TUPLE_ELEM(3, 2, state),\ BOOST_PP_DIV(\ BOOST_PP_MOD(\ BOOST_PP_TUPLE_ELEM(3, 0, state),\ BOOST_PP_TUPLE_ELEM(3, 1, state)\ ),\ BOOST_PP_DIV(BOOST_PP_TUPLE_ELEM(3, 1, state),2)\ )\ )\ ) #define BINARY_REPR_SEQ_MACRO(r, state) (state) #define BINARY_REPR_SEQ(x,y) BOOST_PP_FOR((x, y,BOOST_PP_SEQ_NIL), BINARY_REPR_SEQ_PRED,BINARY_REPR_SEQ_OP,BINARY_REPR_SEQ_MACRO) /// /// BINARY_REP(x,y) extracts the binary representation frm the sequence above /// BINARY_REPR_SEQ(17, 32) generates: /// (1)(0)(0)(0)(1) /// #define BIN_REP_LAST_TUPLE(x,y) BOOST_PP_SEQ_ELEM(BOOST_PP_SUB(BOOST_PP_SEQ_SIZE(BINARY_REPR_SEQ(x,y)),1), BINARY_REPR_SEQ(x,y)) #define BINARY_REP(x,y) BOOST_PP_TUPLE_ELEM(3, 2, BIN_REP_LAST_TUPLE(x,y)) /// /// generates the binary representations of all the numbers from 1 to 2^x -1 /// COMBINATIONS(5) expands to /// ((0)(0)(0)(0)(1)) ((0)(0)(0)(1)(0)) ((0)(0)(0)(1)(1)) ((0)(0)(1)(0)(0)) ((0)(0)(1)(0)(1)) ((0)(0)(1)(1)(0)) ((0)(0)(1)(1)(1)) ((0)(1)(0)(0)(0)) ((0)(1)(0)(0)(1)) ((0)(1)(0)(1)(0)) ((0)(1)(0)(1)(1)) ((0)(1)(1)(0)(0)) ((0)(1)(1)(0)(1)) ((0)(1)(1)(1)(0)) ((0)(1)(1)(1)(1)) ((1)(0)(0)(0)(0)) ((1)(0)(0)(0)(1)) ((1)(0)(0)(1)(0)) ((1)(0)(0)(1)(1)) ((1)(0)(1)(0)(0)) ((1)(0)(1)(0)(1)) ((1)(0)(1)(1)(0)) ((1)(0)(1)(1)(1)) ((1)(1)(0)(0)(0)) ((1)(1)(0)(0)(1)) ((1)(1)(0)(1)(0)) ((1)(1)(0)(1)(1)) ((1)(1)(1)(0)(0)) ((1)(1)(1)(0)(1)) ((1)(1)(1)(1)(0)) ((1)(1)(1)(1)(1)) /// #define COMBINATIONS_MACRO(r,data,elem) (BINARY_REP( BOOST_PP_TUPLE_ELEM(2,0,elem), POWER2(data) )) #define COMBINATIONS(x) BOOST_PP_SEQ_FOR_EACH(COMBINATIONS_MACRO, x, FROM_1_TO_2_POWER_x_MINUS_1(x)) #define PRED6(r,state) BOOST_PP_SEQ_SIZE(BOOST_PP_TUPLE_ELEM(4,0,state)) #define OP6(r,state) (\ BOOST_PP_SEQ_POP_FRONT(BOOST_PP_TUPLE_ELEM(4,0,state)),\ BOOST_PP_IF( BOOST_PP_SEQ_ELEM(0,BOOST_PP_TUPLE_ELEM(4,0,state)),\ BOOST_PP_CAT(\ BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(4,1,state),_),\ BOOST_PP_TUPLE_ELEM(2,1,BOOST_PP_SEQ_ELEM(\ BOOST_PP_TUPLE_ELEM(4,3,state),\ BOOST_PP_TUPLE_ELEM(4,2,state)\ )\ )\ ),\ BOOST_PP_TUPLE_ELEM(4,1,state)\ ),\ BOOST_PP_TUPLE_ELEM(4,2,state),\ BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(4,3,state))\ ) #define OP7(r,state) (\ BOOST_PP_SEQ_POP_FRONT(BOOST_PP_TUPLE_ELEM(4,0,state)),\ BOOST_PP_IF( BOOST_PP_SEQ_ELEM(0,BOOST_PP_TUPLE_ELEM(4,0,state)),\ BOOST_PP_TUPLE_ELEM(4,1,state) \ BOOST_PP_TUPLE_ELEM(2,0,BOOST_PP_SEQ_ELEM(\ BOOST_PP_TUPLE_ELEM(4,3,state),\ BOOST_PP_TUPLE_ELEM(4,2,state)\ )\ ) \ BOOST_PP_TUPLE_ELEM(2,1,BOOST_PP_SEQ_ELEM(\ BOOST_PP_TUPLE_ELEM(4,3,state),\ BOOST_PP_TUPLE_ELEM(4,2,state)\ )\ );,\ BOOST_PP_TUPLE_ELEM(4,1,state)\ ),\ BOOST_PP_TUPLE_ELEM(4,2,state),\ BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(4,3,state))\ ) #define MACRO4(r, data, elem) BOOST_PP_TUPLE_ELEM(4, 1, BOOST_PP_WHILE(PRED6, OP6, (elem,struct params,data,0)))\ { BOOST_PP_TUPLE_ELEM(4, 1, BOOST_PP_WHILE(PRED6, OP7, (elem,,data,0))) }; #define STRUCT_MEMBERS_COMBINATIONS_SEQ(seq) BOOST_PP_SEQ_FOR_EACH(MACRO4, seq, COMBINATIONS(BOOST_PP_SEQ_SIZE(seq))) STRUCT_MEMBERS_COMBINATIONS_SEQ(STRUCT_MEMBERS_SEQ)