boost::mpl::map and boost::mpl::for_each -- code does not compile -- any help appreciated

#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

AMDG peter_foelsche@agilent.com wrote:
template<typename I2E_PAIR, typename E2I>
struct CCreatePair:boost::mpl::pair<typename I2E_PAIR::first, boost::mpl::at<E2I, typename I2E_PAIR::second> >
typename boost::mpl::at<...>::type
{
};
struct CDoSomething
{ template<unsigned int INDEX0, unsigned int INDEX1>
template<int INDEX0, int INDEX1> gcc is picky about the types matching.
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>
boost::mpl::lambda<CCreatePair<boost::mpl::_1, CMapReverse> >::type I'm not sure why the lambda is needed, but otherwise, the compiler tries to instantiate CCreatePair<boost::mpl::_1, CMapReverse> In Christ, Steven Watanabe
participants (2)
-
peter_foelsche@agilent.com
-
Steven Watanabe