diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index e791875..5c763a7 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -984,7 +984,6 @@ template return static_cast>(value); } - // Returns underlying value from enum value. template [[nodiscard]] constexpr auto enum_underlying(E value) noexcept -> detail::enable_if_t> { @@ -1014,6 +1013,15 @@ template } } +// Obtains index in enum values from static storage enum variable. +template +[[nodiscard]] constexpr auto enum_index() noexcept -> detail::enable_if_t { + constexpr auto index = enum_index>(V); + static_assert(index, "magic_enum::enum_index enum value does not have a index."); + + return *index; +} + // Returns name from static storage enum variable. // This version is much lighter on the compile times and is not restricted to the enum_range limitation. template @@ -1063,7 +1071,7 @@ template return {}; // Invalid value or out of range. } else { - return string{enum_name(value)}; + return string{enum_name(value)}; } } @@ -1079,6 +1087,9 @@ template return detail::entries_v>; } +// Allows you to write magic_enum::enum_cast("bar", magic_enum::case_insensitive); +inline constexpr auto case_insensitive = detail::case_insensitive{}; + // Obtains enum value from integer value. // Returns optional with enum value. template @@ -1119,9 +1130,6 @@ template } } -// Allows you to write magic_enum::enum_cast("bar", magic_enum::case_insensitive); -inline constexpr auto case_insensitive = detail::case_insensitive{}; - // Obtains enum value from name. // Returns optional with enum value. template > @@ -1173,15 +1181,6 @@ template > } } -// Obtains index in enum values from static storage enum variable. -template -[[nodiscard]] constexpr auto enum_index() noexcept -> detail::enable_if_t { - constexpr auto index = enum_index>(V); - static_assert(index, "magic_enum::enum_index enum value does not have a index."); - - return *index; -} - // Checks whether enum contains enumerator with such enum value. template [[nodiscard]] constexpr auto enum_contains(E value) noexcept -> detail::enable_if_t {