Question
Is it possible to detect whether an enum has no fixed underlying type?
I have a template function that operates on a generic type T
as input. I statically assert that T
is an enum.
However, I want to constrain it further so that C-style enums (i.e. without fixed (explicit) underlying type) cannot be passed. Otherwise, the implementation risks invoking Undefined Behavior due to this (emphasis mine):
A value of integer or enumeration type can be converted to any complete enumeration type. If the underlying type is not fixed, the behavior is undefined if the value of expression is out of range (the range is all values possible for the smallest bit-field large enough to hold all enumerators of the target enumeration).
Is it possible to achieve this? If so, how?