| 39 | |
| 40 | template <typename E, std::enable_if_t<std::is_enum_v<std::decay_t<E>>, int> = 0> |
| 41 | std::string format_as(E e) { |
| 42 | using D = std::decay_t<E>; |
| 43 | static_assert(std::is_same_v<char, magic_enum::string_view::value_type>, "magic_enum::formatter requires string_view::value_type type same as char."); |
| 44 | if constexpr (magic_enum::detail::supported<D>::value) { |
| 45 | if constexpr (magic_enum::detail::subtype_v<D> == magic_enum::detail::enum_subtype::flags) { |
| 46 | if (const auto name = magic_enum::enum_flags_name<D>(e); !name.empty()) { |
| 47 | return {name.data(), name.size()}; |
| 48 | } |
| 49 | } else { |
| 50 | if (const auto name = magic_enum::enum_name<D>(e); !name.empty()) { |
| 51 | return {name.data(), name.size()}; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | return std::to_string(magic_enum::enum_integer<D>(e)); |
| 56 | } |
| 57 | |
| 58 | } // namespace magic_enum::format |
| 59 | |