
Bruce Trask <Bruce.Trask@prismtech.com> writes:
Hi,
I coded up the mpl::map versus the SWITCH approach and I am thinking that the SWITCH approach is better in this case as it shows the various mnemonic choices at the point of the SWITCH. Thoughts?
You can't meaningfully compare the syntax of the map with something that has unspecified syntax (i.e. switch) ;-) In MPL, the closest thing to switch is currently spelled: eval_if< is_same<c1,x> , identity<r1> , eval_if< is_same<c2,x> , identity<r2> ... , eval_if< is_same<cn,x> , identity<rn> , identity<default_> > >
Also if the SWITCH is the better way to go, it leads me to my original question as to whether there is a mpl::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; } };
typedef mpl::map< mpl::pair<mpl::integral_c<tagit, one>, First>, mpl::pair<mpl::integral_c<tagit, two>, Second>, mpl::pair<mpl::integral_c<tagit, three>, Third> > funcchooser;
Ehm, if that's all you need to do: template <int> func_; template <> struct func_<1> { static void func() { cout << "First" << endl }}; template <> struct func_<2> { static void func() { cout << "Second" << endl }}; template <> struct func_<3> { static void func() { cout << "Third" << endl }}; template<tagit ti> void funcCaller() { func_<ti>::func(); } -- Dave Abrahams Boost Consulting www.boost-consulting.com