Angus Leeming
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::setfoo::state2() { return foo::state2; }
template <> foo foo::setfoo::state3() { return foo::state3; }
int main() { // Compiles, as expected. foo f1 = foo::setfoo::state2(); foo f2(foo::setfoo::state2()); // Fail to compile, as expected. // foo f3 = foo::setfoo::state1(); // foo f4(foo::setfoo::state1());
return 0; }
-- Dave Abrahams Boost Consulting www.boost-consulting.com