//Purpose: // Show how binding_of any's with bindings CTOR arg // are related to binding_of tuple. // #include #include #include #include #include #include #include #include namespace mpl = boost::mpl; namespace te = boost::type_erasure; using te::_a; using te::_b; void multi2() { typedef double value_t; value_t array[5]={1,2,3,4,5}; typedef mpl::vector< te::copy_constructible<_a>, te::copy_constructible<_b>, te::typeid_<_a>, te::addable<_a, _b, _a> > requirements; typedef int displacement_t; typedef value_t* value_ptr_t; typedef mpl::map< mpl::pair<_a, value_ptr_t>, mpl::pair<_b, displacement_t> > bindings_map; //Create arguments to constructors on stack: mpl::at::type stack_value_ptr_v=&array[0]; mpl::at::type stack_displacement_v=2; //Illustrate doing a operator+ starting from tuple. te::tuple tuple_v(stack_value_ptr_v, stack_displacement_v); te::any tuple_displaced_value_ptr_v(te::get<0>(tuple_v) + te::get<1>(tuple_v)); value_ptr_t tuple_cast_value_ptr_v=te::any_cast(tuple_displaced_value_ptr_v); std::cout<<(tuple_cast_value_ptr_v==stack_value_ptr_v+stack_displacement_v)<<"\n"; //Something similar using bindings and just any's. te::static_binding bindings_made=te::make_binding(); te::any bindings_value_ptr_v(stack_value_ptr_v,bindings_made); te::any bindings_displacement_v(stack_displacement_v,bindings_made); te::any bindings_displaced_value_ptr_v(bindings_value_ptr_v + bindings_displacement_v); value_ptr_t bindings_cast_value_ptr_v=te::any_cast(bindings_displaced_value_ptr_v); std::cout<<(bindings_cast_value_ptr_v==stack_value_ptr_v+stack_displacement_v)<<"\n"; std::cout<<(te::binding_of(tuple_displaced_value_ptr_v)==te::binding_of(bindings_displaced_value_ptr_v))<<"\n"; } int main() { multi2(); return 0; }