Daily bit(e) of C++ | std::to_underlying
Daily bit(e) of C++ ♻️32, The single-purpose cast for converting enumerators to the underlying value: std::to_underlying.
The std::to_underlying is a C++23 single-purpose cast that converts an enumerator to the underlying integral type of the enumeration.
This single-step approach replaces the previous approach using static_cast in combination with the C++11 std::underlying_type utility. The std::underlying_type utility is required since the underlying type of unscoped enumerations is implementation-defined.