If you really need to iterate over the enum class, and you want to avoid adding a special END character, you can define your own traits for this purpose.
template<typename E> struct EnumTraits; enum class E { V1, V2, V3 }; enum class F { X1, X2, X3 }; template<> struct EnumTraits<E> { static constexpr E LAST = E::V3; }; template<> struct EnumTraits<F> { static constexpr F LAST = F::X3; };
Then you can write, for example:
EnumTraits<E>::LAST
to get the "final" value of E. Of course, you still need to define arithmetic operations on this class.
witosx
source share