Can I define a type to use as the underlying type of an enumeration? Something like this:
struct S {
S(int i) : value(i) {}
operator int() { return value; }
int value;
};
enum E : S {
A, B, C
};
The error message tells me that S must be an integral type. I have tried to specialize std::is_integral
like the following, but it seems that in this context, "integral type" really means one of the fundamental types.
namespace std {
template<>
struct is_integral<S> : public true_type {};
}
So, using any version of C++, is there a way to make a custom type pass off as an integral type?