
#include <boost/mpl/map.hpp> #include <iostream> #include <boost/mpl/at.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/mpl/for_each.hpp> typedef boost::mpl::map< boost::mpl::pair< boost::mpl::int_<0>, boost::mpl::int_<3> >, boost::mpl::pair< boost::mpl::int_<1>, boost::mpl::int_<2> >, boost::mpl::pair< boost::mpl::int_<2>, boost::mpl::int_<1> >, boost::mpl::pair< boost::mpl::int_<3>, boost::mpl::int_<0> >
CMapForward;
typedef boost::mpl::map< boost::mpl::pair< boost::mpl::int_<0>, boost::mpl::int_<3> >, boost::mpl::pair< boost::mpl::int_<1>, boost::mpl::int_<2> >, boost::mpl::pair< boost::mpl::int_<2>, boost::mpl::int_<1> >, boost::mpl::pair< boost::mpl::int_<3>, boost::mpl::int_<0> >
CMapReverse;
template<typename I2E_PAIR, typename E2I> struct CCreatePair:boost::mpl::pair<typename I2E_PAIR::first, boost::mpl::at<E2I, typename I2E_PAIR::second> > { }; struct CDoSomething { template<unsigned int INDEX0, unsigned int INDEX1> inline void operator()(const boost::mpl::pair<boost::mpl::int_<INDEX0>, boost::mpl::int_<INDEX1> > &_r) const { std::cout << INDEX0 << " " << INDEX1 << "\n"; } }; int main(int, char**) { boost::mpl::for_each< CMapForward, template CCreatePair<boost::mpl::_1, CMapReverse> >(CDoSomething()); return 0; } "The first point (using an init() function in preference to a constructor) is bogus. Using constructors and exception handling is a more general and systematic way of dealing with resource acquisition and initialization errors. This style is a relic of pre-exception C++." -- Stroustrup