#include #include #include #include #include #include struct mpl_sequence_flatter_tail { typedef mpl_sequence_flatter_tail super; typedef boost::tuples::null_type type; }; template struct mpl_sequence_flatter:Super { typedef Super super; typedef Type type; }; struct mpl_sequence_flatter_applier { template struct apply { typedef mpl_sequence_flatter type; }; }; #define AUX_pred(r,state) BOOST_PP_TUPLE_ELEM(2,0,state) #define AUX_op(r,state) \ ( \ BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(2, 0, state)), \ BOOST_PP_TUPLE_ELEM(2, 1, state)::super \ ) #define AUX_macro(r,state) ,typename BOOST_PP_TUPLE_ELEM(2, 1, state)::type template struct composite_key_from_sequence { typedef typename boost::mpl::reverse_fold< Sequence, mpl_sequence_flatter_tail, mpl_sequence_flatter_applier >::type aux; typedef boost::multi_index::composite_key< Value BOOST_PP_FOR( (BOOST_MULTI_INDEX_LIMIT_COMPOSITE_KEY_SIZE,aux), AUX_pred,AUX_op,AUX_macro ) > type; }; #undef AUX_pred #undef AUX_op #undef AUX_macro /**************** testing ****************/ #include #include #include #include #include #include #include using namespace boost; using namespace boost::multi_index; using namespace std; struct employee { string name; int age; int salary; int ssn; }; typedef member member0_type; typedef member member1_type; typedef member member2_type; typedef member member3_type; typedef mpl::vector vector0_type; typedef mpl::push_back< vector0_type,member1_type>::type vector1_type; typedef mpl::push_back< vector1_type,member2_type>::type vector2_type; typedef mpl::push_back< vector2_type,member3_type>::type vector3_type; typedef mpl::list< member3_type,member2_type, member1_type,member0_type> list0_type; BOOST_MPL_ASSERT(( is_same< composite_key_from_sequence::type, composite_key > )); BOOST_MPL_ASSERT(( is_same< composite_key_from_sequence::type, composite_key > )); BOOST_MPL_ASSERT(( is_same< composite_key_from_sequence::type, composite_key > )); BOOST_MPL_ASSERT(( is_same< composite_key_from_sequence::type, composite_key > )); BOOST_MPL_ASSERT(( is_same< composite_key_from_sequence::type, composite_key > )); int main(){}