//Purpose: // Demo the conversion using binding // #include #include #include #include #include #include #include #include #define BOOST_CHECK_EQUAL(X,Y) BOOST_ASSERT(X==Y) using namespace boost::type_erasure; template struct common : ::boost::mpl::vector < copy_constructible , typeid_ > {}; template < unsigned Tag > struct type_uns { unsigned const my_tag; type_uns(): my_tag(Tag) { std::cout<<"type_uns<"<()\n"; } type_uns( type_uns const&other): my_tag(Tag) { std::cout<<"type_uns<"<( type_uns const&other.my_tag="<::operator=( type_uns const&other.my_tag="< bool operator== ( type_uns const& , type_uns const& ) { return true; } template < typename Concept1 , typename Tag1 , typename Concept2 > bool same_concrete ( any const& a_any1 , binding const& a_bind2 ) /**@brief * is actual type of Tag1 in a_any1 == actual type of Tag1 in a_bind2 ? */ { std::type_info const& info1=typeid_of(a_any1); std::type_info const& info2=typeid_of(a_bind2); return info1 == info2; } int main() { typedef type_uns<0> src_concrete_t; typedef type_uns<1> dst_concrete_t; typedef ::boost::mpl::vector > the_concept; typedef ::boost::mpl::map > src_mmap; typedef ::boost::mpl::map > dst_mmap; static_binding src_smap=make_binding(); static_binding dst_smap=make_binding(); binding dst_binding(dst_smap); src_concrete_t src_concrete_v; any src_a( src_concrete_v, src_smap); BOOST_CHECK_EQUAL(any_cast(src_a), src_concrete_v); #define CHECK_CONCRETE #ifdef CHECK_CONCRETE BOOST_ASSERT(same_concrete(src_a, dst_binding)); #endif any dst_a( src_a, dst_binding); dst_concrete_t dst_concrete_v; BOOST_CHECK_EQUAL(any_cast(dst_a), dst_concrete_v); return 0; }