fix nameof_enum for pure enum type

This commit is contained in:
terik23 2019-03-23 17:16:41 +05:00
parent 13105a2839
commit ec4429b35d
2 changed files with 10 additions and 10 deletions

View file

@ -156,21 +156,21 @@ struct nameof_enum_t final {
[[nodiscard]] constexpr std::string_view operator()(int value) const noexcept { [[nodiscard]] constexpr std::string_view operator()(int value) const noexcept {
switch (value - V) { switch (value - V) {
case 0: case 0:
return nameof_enum_impl<E, E{V}>(); return nameof_enum_impl<E, static_cast<E>(V)>();
case 1: case 1:
return nameof_enum_impl<E, E{V + 1}>(); return nameof_enum_impl<E, static_cast<E>(V + 1)>();
case 2: case 2:
return nameof_enum_impl<E, E{V + 2}>(); return nameof_enum_impl<E, static_cast<E>(V + 2)>();
case 3: case 3:
return nameof_enum_impl<E, E{V + 3}>(); return nameof_enum_impl<E, static_cast<E>(V + 3)>();
case 4: case 4:
return nameof_enum_impl<E, E{V + 4}>(); return nameof_enum_impl<E, static_cast<E>(V + 4)>();
case 5: case 5:
return nameof_enum_impl<E, E{V + 5}>(); return nameof_enum_impl<E, static_cast<E>(V + 5)>();
case 6: case 6:
return nameof_enum_impl<E, E{V + 6}>(); return nameof_enum_impl<E, static_cast<E>(V + 6)>();
case 7: case 7:
return nameof_enum_impl<E, E{V + 7}>(); return nameof_enum_impl<E, static_cast<E>(V + 7)>();
default: default:
return nameof_enum_t<E, V + 8>{}(value); return nameof_enum_t<E, V + 8>{}(value);
} }
@ -241,7 +241,7 @@ template <typename T, typename = std::enable_if_t<!std::is_reference_v<T>>>
template <typename T, typename = std::enable_if_t<std::is_enum_v<std::decay_t<T>>>> template <typename T, typename = std::enable_if_t<std::is_enum_v<std::decay_t<T>>>>
[[nodiscard]] constexpr std::string_view nameof_enum(T value) noexcept { [[nodiscard]] constexpr std::string_view nameof_enum(T value) noexcept {
constexpr auto s = std::is_signed_v<std::underlying_type_t<std::decay_t<T>>>; constexpr bool s = std::is_signed_v<std::underlying_type_t<std::decay_t<T>>>;
return detail::nameof_enum_t<std::decay_t<T>, s ? -NAMEOF_ENUM_MAX_SEARCH_DEPTH : 0>{}(static_cast<int>(value)); return detail::nameof_enum_t<std::decay_t<T>, s ? -NAMEOF_ENUM_MAX_SEARCH_DEPTH : 0>{}(static_cast<int>(value));
} }

View file

@ -69,7 +69,7 @@ struct Long {
enum class Color { RED = -1, GREEN, BLUE }; enum class Color { RED = -1, GREEN, BLUE };
enum Directions : int { Up, Down, Right, Left}; enum Directions { Up, Down, Right, Left};
SomeStruct struct_var; SomeStruct struct_var;
Long othervar; Long othervar;