#include #include #include #include #include #include #include #include #include #include #include namespace mpl = boost::mpl; using namespace mpl::placeholders; //============================================================================= template struct join_maps_1 { typedef typename mpl::copy< mpl::joint_view , mpl::inserter< mpl::map<>, mpl::insert<_1, _2> > >::type type; }; //============================================================================= template struct join_maps_2 { typedef typename mpl::copy< MapR , mpl::inserter< MapL, mpl::insert<_1, _2> > >::type type; }; //============================================================================= template struct print {}; //============================================================================= template std::ostream& operator<<(std::ostream& out, const print&) { out << i; return out; } //============================================================================= struct map_printer { template inline void operator() (T) const { std::cout << " " << typename T::second(); } }; /*###################################################################*/ int main(int argc, const char* argv[]) { //Create a couple of maps using insert (this replicates the actual code) typedef mpl::insert, mpl::pair< mpl::int_<0>, print<0> > >::type map0; typedef mpl::insert, print<1> > >::type map1; typedef mpl::insert, print<2> > >::type map2; typedef mpl::insert, mpl::pair< mpl::int_<3>, print<3> > >::type map3; typedef mpl::insert, print<4> > >::type map4; typedef mpl::insert, print<5> > >::type map5; //Erease a couple of keys typedef mpl::erase_key >::type map_erase1; typedef mpl::erase_key >::type map_erase2; //Join the maps into a single map using method 1 typedef join_maps_1< map2 , map5 >::type join0_1; typedef join_maps_1< map2 , map_erase2 >::type join1_1; typedef join_maps_1< map_erase1, map5 >::type join2_1; typedef join_maps_1< map_erase1, map_erase2 >::type join3_1; //Print out the resuling maps std::cout << std::endl; boost::mpl::for_each< join0_1 >(map_printer()); //Works std::cout << std::endl; boost::mpl::for_each< join1_1 >(map_printer()); //Works std::cout << std::endl; boost::mpl::for_each< join2_1 >(map_printer()); //Works std::cout << std::endl; boost::mpl::for_each< join3_1 >(map_printer()); //Works std::cout << std::endl; //Join the maps into a single map using method 2 typedef join_maps_2< map2 , map5 >::type join0_2; typedef join_maps_2< map2 , map_erase2 >::type join1_2; typedef join_maps_2< map_erase1, map5 >::type join2_2; typedef join_maps_2< map_erase1, map_erase2 >::type join3_2; //Print out the resuling maps std::cout << std::endl; boost::mpl::for_each< join0_2 >(map_printer()); //Works std::cout << std::endl; boost::mpl::for_each< join1_2 >(map_printer()); //Works std::cout << std::endl; boost::mpl::for_each< join2_2 >(map_printer()); //MSVC 9 error (works with CYGWIN GCC 4.3.2 ) std::cout << std::endl; boost::mpl::for_each< join3_2 >(map_printer()); //MSVC 9 error (works with CYGWIN GCC 4.3.2 ) std::cout << std::endl; }