#include #include #include #include #include #include #include #include #include using namespace std; namespace mpl = boost::mpl; //using namespace mpl::placeholders; template struct IF { typedef Then RET; }; template struct IF { typedef Else RET; }; /////////// SWITCH const int DEFAULT = ~(~0u >> 1); const int nilValue = DEFAULT+1; struct NilCase { }; template struct CASE { enum { tag = tag_ }; typedef Type_ Type; typedef Next_ Next; }; template class SWITCH { typedef typename Case::Next NextCase; enum { caseTag = Case::tag, found = (caseTag == tag || caseTag ==DEFAULT) }; public: typedef typename IF::RET>::RET RET; }; template class SWITCH { public: typedef NilCase RET; }; ////////// END SWITCH enum tagit { one, two, three }; struct First { static void func() { cout << "First" << endl; } }; struct Second { static void func() { cout << "Second" << endl; } }; struct Third { static void func() { cout << "Third" << endl; } }; struct Default { static void func() { cout << "Third" << endl; } }; typedef mpl::map< mpl::pair, First>, mpl::pair, Second>, mpl::pair, Third> > funcchooser; template void funcCaller() { mpl::eval_if< boost::is_same, mpl::integral_c >, mpl::identity, mpl::eval_if< boost::is_same, mpl::integral_c >, mpl::identity, mpl::eval_if< boost::is_same, mpl::integral_c >, mpl::identity, mpl::identity > > >::type::func(); SWITCH > > >::RET::func(); mpl::at >::type::func(); } int main() { funcCaller(); funcCaller(); funcCaller(); return 0; }