As we know, incrementation and decrementation of enum
in C++03 is illegal, because C++03 enum
may not be continuous. But the C++11 standard introduced the new enum class
construction, which, according to Wikipedia, is more type-safe because it isn’t built on any simple countable type. So now, if we have a bounded list of values of an enum, can we write something like
enum class Colors { Black, Blue, White };
// ...
Colors color = Colors::White;
color++;
and will it work correctly (e.g. incrementation of White
will return Black
and decrementation of Black
will return White
)?
If we can't write such code, do you know any behavior-like classes either from boost
or from Qt
that provide us this feature (correct in- and decrementing)?