Add fmt::underlying for enum classes

This commit is contained in:
Victor Zverovich
2022-01-22 08:06:22 -08:00
parent 0014024a2c
commit 09fde7f4b8
3 changed files with 25 additions and 1 deletions

View File

@@ -2675,6 +2675,22 @@ template <typename T> auto ptr(const std::shared_ptr<T>& p) -> const void* {
return p.get();
}
/**
\rst
Converts ``e`` to the underlying type.
**Example**::
enum class color { red, green, blue };
auto s = fmt::format("{}", fmt::underlying(color::red));
\endrst
*/
template <typename Enum>
constexpr auto underlying(Enum e) noexcept ->
typename std::underlying_type<Enum>::type {
return static_cast<typename std::underlying_type<Enum>::type>(e);
}
class bytes {
private:
string_view data_;