//ChangeLog: // 2011-01-07.1919CST // copied from attachment to: // http://article.gmane.org/gmane.comp.lib.boost.user/64988 // 2011-01-07.22309CST // Added one_of_maybe code and macro to switch beteen // that and boost::variant implementations. // #define VARIANT_TEST_SIZE 10 #define USE_SHARED_PTR 1 #define USE_ONE_OF_MAYBE 0 #if USE_ONE_OF_MAYBE #else #include #include #include #include #endif #if USE_SHARED_PTR #include #endif #include #include #include #define BOOST_PP_LOCAL_MACRO(n) class BOOST_PP_CAT(C, n) { public: int i; }; #define BOOST_PP_LOCAL_LIMITS (0, VARIANT_TEST_SIZE) #include BOOST_PP_LOCAL_ITERATE() #if USE_SHARED_PTR #define VARIANT_ARG(z, n, data) boost::shared_ptr /**/ #else #define VARIANT_ARG(z, n, data) BOOST_PP_CAT(C, n) /**/ #endif #if USE_ONE_OF_MAYBE #include typedef boost::composite_storage::pack::container < boost::composite_storage::tags::one_of_maybe , boost::mpl::integral_c , BOOST_PP_ENUM(VARIANT_TEST_SIZE, VARIANT_ARG, ~) > v_t; #else typedef boost::mpl::vector Mplv_t; typedef boost::make_variant_over::type v_t; #endif void foo(const v_t& v) { //C: Copy variant using assignment operator v_t v2; v2 = v; } int main() { v_t v; foo(v); return 0; }