//Purpose: // Demo the conversion using binding // #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 { void operator++(){} }; template < unsigned Tag > bool operator== ( type_uns const& , type_uns const& ) { return true; } template < typename Bind1 , typename Bind2 > bool same_concrete ( Bind1 const& bind1 , Bind2 const& bind2 ) { //tests whether bind1 and bind2 have same placeholders //*and* the actual types are same. // return false //obviously not actual implementation. //Actual implementation could possibly use //some type of visitor pattern to find and compare //the actual types associated with the placeholders. ; } void test() { 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); any dst_a( src_a, dst_binding); BOOST_ASSERT(same_concrete(binding_of(src_a), dst_binding)); dst_concrete_t dst_concrete_v; BOOST_CHECK_EQUAL(any_cast(dst_a), dst_concrete_v); } int main() { test(); return 0; }