MCPcopy Create free account
hub / github.com/Neargye/magic_enum / format_as

Function format_as

include/magic_enum/magic_enum_format.hpp:41–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40template <typename E, std::enable_if_t<std::is_enum_v<std::decay_t<E>>, int> = 0>
41std::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

Callers

nothing calls this directly

Calls 4

to_stringFunction · 0.85
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected