//Purpose: // Demonstrate the different purposes of different // "kinds" of boost::type_erasure::any CTOR's. //References: // [ConsKind] // http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/doc/html/boost_typeerasure/design.html#boost_typeerasure.design.constructors #include #include #include namespace mpl = boost::mpl; using namespace boost::type_erasure; template < unsigned ThisId > struct v { }; int main() { typedef mpl::vector< copy_constructible<_a>, #define COPY_CTOR_V0 #ifdef COPY_CTOR_V0 constructible<_a(v<0>const&)> /** * allows y(a_binding, v0) * (enabled when defined(PH2VALUE),see below) * to compile. */ #endif > a_concept; typedef any< a_concept, _a> a_any; v<0> v0; a_any x( v0); /** * The CTOR for x does no dispatching, it simply * calls the decltype(v0) CTOR with argument, v0. * * This is a binding constructor, as defined in [ConsKind]. */ bindingconst&a_binding=binding_of(x); a_any y ( a_binding, /** * This a_binding argument makes * the constructor for y a dispatching constructor, * according to item 2 in the 2nd numbered list in [ConsKind]. * * Hence, the args after this 1st arg must * match one of the concepts in a_concept. */ #define PH2VALUE #ifndef PH2VALUE x /** * With this argument, * this y declaration * matches concept: * constructible<_a(const _a&)> * where the 1st _a must match decltype(y) * (because that's what is being constructed), * and the 2nd _a must match decltype(x) * (because that's the only argument), * and decltype(y) == decltype(x). * * Since constructible<_a(const_a&)> * is included in copy_constructibe<_a>, * and copy_constructibe<_a> is in a_concept, * this will compile. */ #else v0 /** * With this argument, this y declaration * does not match concept: * constructible * because, * but does match concept: * constructible<_a(const& v<0>)> * Hence, for this to compile, a_concept must * include the latter concept. */ #endif ); return 0; }