//Purpose: // See if an any can change the stored type with an assignment. // #include #include #include #include #include #include #include namespace mpl = boost::mpl; namespace te = boost::type_erasure; using te::_a; using te::_b; typedef mpl::vector < te::copy_constructible<_a> , te::copy_constructible<_b> , te::typeid_<_a> , te::typeid_<_b> > requirements; typedef double value_t; typedef value_t* value_ptr_t; typedef int displacement_t; typedef mpl::vector<_a,_b> placeholders; typedef mpl::vector types; typedef mpl::map< mpl::pair::type, mpl::at_c::type>, mpl::pair::type, mpl::at_c::type> > bindings_map_t; void convert() { value_t array[5]={1,2,3,4,5}; //Create arguments to constructors on stack: mpl::at::type stk_value_ptr_v=&array[0]; mpl::at::type stk_displacement_v=2; te::static_binding bindings_made=te::make_binding(); //Can default any be created? te::any bnd_value_ptr_v(stk_value_ptr_v,bindings_made); { std::type_info const& tinfo=te::typeid_of(bnd_value_ptr_v); std::cout <<"typeinfo(bnd_value_ptr_v)=" < bnd_displacement_v(stk_displacement_v,bindings_made); { std::type_info const& tinfo=te::typeid_of(bnd_displacement_v); std::cout <<"typeinfo(bnd_displacement_v)=" <=" <<::boost::any_cast(&a_any) <<"\n"; a_any=stk_value_ptr_v; std::cout <<"a_any=stk_value_ptr_v; any_cast=" <<::boost::any_cast(&a_any) <<"; any_cast=" <<::boost::any_cast(&a_any) <<"\n"; } } int main() { convert(); return 0; }