diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 005f81d..7d3fc9a 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -326,9 +326,8 @@ namespace ops { template , typename = detail::enable_if_enum_t> std::ostream& operator<<(std::ostream& os, E value) { static_assert(std::is_enum_v, "magic_enum::ops::operator<< requires enum type."); - const auto name = detail::name_impl(static_cast(value)); - if (!name.empty()) { + if (auto name = detail::name_impl(static_cast(value)); !name.empty()) { os << name; } @@ -340,8 +339,7 @@ std::ostream& operator<<(std::ostream& os, std::optional value) { static_assert(std::is_enum_v, "magic_enum::ops::operator<< requires enum type."); if (value.has_value()) { - const auto name = detail::name_impl(static_cast(value.value())); - if (!name.empty()) { + if (auto name = detail::name_impl(static_cast(value.value())); !name.empty()) { os << name; } }