The evolution of the C++ language continues to bring powerful features that enhance code safety, readability, and maintainability. Among these improvements, we got changes and additions to enum class functionalities across C++17, C++20, and C++23. In this blog post, we’ll explore these advancements, focusing on initialization improvements in C++17, the introduction of the using enum keyword in C++20, and the std::to_underlying utility in C++23.
Could someone explain to me what the value is in making it really easy to initialize an enum class with a value that is not one of the enumerated values?
Good question. My response would be: only where it is not used as an enum. The example in the article is one example (although I’ve never seen that idiom in the wild) or for doing things like bitfields (the opposite of the
to_underlying
section).