views:

77

answers:

1
+5  A: 

You can do it this way even without boost.mpl:

template< Enumerated Value > struct Enumerated2Type { typedef void type; enum { value = false }; };
#define DEFINE_ENUMERATED_TYPE(TYPE, ENUM) template<> struct Enumerated2Type<ENUM> { typedef TYPE type; enum { value = true }; }
DEFINE_ENUMERATED_TYPE(int, Enum1);
DEFINE_ENUMERATED_TYPE(bool, Enum2);
DEFINE_ENUMERATED_TYPE(double, Enum3);
DEFINE_ENUMERATED_TYPE(std::string, Enum4);

And you check you can do this way:

template <typename ArbitraryType, Enumerated E>
struct check_at_compile_time {
    static bool const value = Enumerated2Type< E >::value && boost::is_same< ArbitraryType, typename Enumerated2Type< E >::type >::value;
};

Untested but should work like this.

Vinzenz