//ChangeLog: // 2011-01-17.1445CST // copied from post with headers: /* From: Paul Newsgroups: gmane.comp.lib.boost.user Subject: Re: large variant performance compared (50 elements) Date: Mon, 17 Jan 2011 21:18:54 +0100 Lines: 66 */ #include #include #include #include #include #include #include "CLoPtrVariant.hpp" #include class CVisitBinary : public Layout::static_visitor { public: template bool operator()(const T&, const U&) const { return false; } template bool operator()(const T&, const T&) const { return true; } }; template void TestVariantBinary() { typedef typename Layout::make_variant_over::type variant_t; variant_t v1_1(boost::shared_ptr(new ElementType1)); variant_t v1_2(boost::shared_ptr(new ElementType1)); variant_t v2_1(boost::shared_ptr(new ElementType2)); BOOST_CHECK(Layout::apply_visitor(CVisitBinary(), v1_1, v1_2)); //Same type BOOST_CHECK(Layout::apply_visitor(CVisitBinary(), v1_1, v1_1)); //Same type, same instance BOOST_CHECK(!Layout::apply_visitor(CVisitBinary(), v1_1, v2_1)); //Different types } //Generate 200 types (class C1, C2, ... C200) #define BOOST_PP_LOCAL_MACRO(n) \ class BOOST_PP_CAT(I, n) \ { \ public: \ }; \ \ class BOOST_PP_CAT(C, n) \ : public BOOST_PP_CAT(I, n) \ { \ public: \ int i; \ }; #define BOOST_PP_LOCAL_LIMITS (0, 200) #include BOOST_PP_LOCAL_ITERATE() //Generate mpl sequences #define SHARED_PTR_C(z, n, data) boost::shared_ptr #define SHARED_PTR_I(z, n, data) boost::shared_ptr typedef boost::mpl::vector MplVectorC10_t; void test() { TestVariantBinary(); //2 phase visitation giving 100 paths }