#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef FAKIE_TAGGED_TUPLE_MAX_ARITY # define FAKIE_TAGGED_TUPLE_MAX_ARITY 10 #elif FAKIE_TAGGED_TUPLE_MAX_ARITY > 10 #error boost::tuples doesn't support arity > 10 #endif namespace fakie { #define FAKIE_TAGGED_TUPLE_DETAIL_TYPES(z, n, text)\ BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(text, BOOST_PP_MUL(2, n)) #define FAKIE_TAGGED_TUPLE_DETAIL_VALUES(z, n, text)\ BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(text, BOOST_PP_ADD(BOOST_PP_MUL(2, n), 1)) #define FAKIE_TAGGED_TUPLE_DETAIL_MPL_2_TUPLE(z, n, text)\ BOOST_PP_COMMA_IF(n)\ typename boost::mpl::if_<\ boost::is_same,\ boost::tuples::null_type,\ BOOST_PP_CAT(text, BOOST_PP_MUL(2, n))\ >::type template struct detail_check_types_and_names : boost::enable_if_c::type::value == boost::mpl::size::type::value> , boost::enable_if::type, Types> > { }; template struct tagged_tuple : boost::tuple { typedef boost::mpl::vector Types; typedef boost::mpl::vector Names; typedef boost::tuple Base; #undef FAKIE_TAGGED_TUPLE_DETAIL_TYPES #undef FAKIE_TAGGED_TUPLE_DETAIL_VALUES #undef FAKIE_TAGGED_TUPLE_DETAIL_MPL_2_TUPLE #define FAKIE_TAGGED_TUPLE_DETAIL_CTORS(z, n, text)\ template\ tagged_tuple(BOOST_PP_ENUM_BINARY_PARAMS(n, U, & u), detail_check_types_and_names * = 0)\ : Base(BOOST_PP_ENUM_PARAMS(n, u)) {} tagged_tuple(detail_check_types_and_names * = 0) {} BOOST_PP_REPEAT_FROM_TO(1, FAKIE_TAGGED_TUPLE_MAX_ARITY, FAKIE_TAGGED_TUPLE_DETAIL_CTORS, _) #undef FAKIE_TAGGED_TUPLE_DETAIL_CTORS using Base::get; template typename boost::tuples::access_traits< typename boost::mpl::at_c< Types, boost::mpl::find::type::pos::value >::type >::non_const_type get () { return boost::tuples::get::type::pos::value>(*this); } template typename boost::tuples::access_traits< typename boost::mpl::at_c< Types, boost::mpl::find::type::pos::value >::type >::const_type get () const { return boost::tuples::get::type::pos::value>(*this); } }; } class name_t {}; class value_t {}; int main() { using namespace fakie; tagged_tuple s; s.get() = "Hello World"; s.get() = 2005; std::cout << s << ' ' << sizeof(s) << ' ' << sizeof(boost::tuple) << ' ' << sizeof(std::string) + sizeof(int); return 0; }