
Angus Leeming <angus.leeming@btopenworld.com> writes:
What are the advantages of the Boost.MPL approach over the functionally identical:
#include <iostream>
class foo { public: enum state { state1, state2, state3 };
// Only the specializations (below) of this template will compile. template <int N> static foo set() { return invalid_value; }
Without a definition for invalid_value, this is invalid code, and on a conforming compiler, compilation fails at the point it is parsed.
private: foo(state) { std::cout << "foo" << std::endl; } };
template <> foo foo::set<foo::state2>() { return foo::state2; }
template <> foo foo::set<foo::state3>() { return foo::state3; }
int main() { // Compiles, as expected. foo f1 = foo::set<foo::state2>(); foo f2(foo::set<foo::state2>()); // Fail to compile, as expected. // foo f3 = foo::set<foo::state1>(); // foo f4(foo::set<foo::state1>());
return 0; }
-- Dave Abrahams Boost Consulting www.boost-consulting.com