diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index e378051..b488727 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -134,9 +134,8 @@ template [[nodiscard]] constexpr std::string_view name_impl(int value) noexcept { static_assert(std::is_enum_v, "magic_enum::detail::name_impl requires enum type."); constexpr auto names = strings_impl(range_impl()); - const int i = value - min_impl(); - if (i >= 0 && static_cast(i) < names.size()) { + if (int i = value - min_impl(); i >= 0 && static_cast(i) < names.size()) { return names[i]; } else { return {}; // Value out of range.