diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index baa2614..852714d 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -394,13 +394,7 @@ std::basic_ostream& operator<<(std::basic_ostream& o static_assert(detail::check_enum_v, "magic_enum::ostream_operators::operator<< requires enum type."); if (value.has_value()) { - if (auto name = detail::name_impl(value.value()); !name.empty()) { - for (auto c : name) { - os.put(c); - } - } else { - os << static_cast>(value.value()); - } + os << value.value(); } return os; diff --git a/test/test.cpp b/test/test.cpp index 8770816..1921070 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -299,28 +299,32 @@ TEST_CASE("ostream_operators") { REQUIRE(ss.str() == name); }; - test_ostream(Color::RED, "RED"); + test_ostream(std::make_optional(Color::RED), "RED"); test_ostream(Color::GREEN, "GREEN"); test_ostream(Color::BLUE, "BLUE"); test_ostream(static_cast(0), "0"); + test_ostream(std::make_optional(static_cast(0)), "0"); - test_ostream(Numbers::one, "one"); + test_ostream(std::make_optional(Numbers::one), "one"); test_ostream(Numbers::two, "two"); test_ostream(Numbers::three, "three"); test_ostream(Numbers::many, "127"); test_ostream(static_cast(0), "0"); + test_ostream(std::make_optional(static_cast(0)), "0"); - test_ostream(Directions::Up, "Up"); + test_ostream(std::make_optional(Directions::Up), "Up"); test_ostream(Directions::Down, "Down"); test_ostream(Directions::Right, "Right"); test_ostream(Directions::Left, "Left"); test_ostream(static_cast(0), "0"); + test_ostream(std::make_optional(static_cast(0)), "0"); - test_ostream(number::one, "one"); + test_ostream(std::make_optional(number::one), "one"); test_ostream(number::two, "two"); test_ostream(number::three, "three"); test_ostream(number::four, "400"); test_ostream(static_cast(0), "0"); + test_ostream(std::make_optional(static_cast(0)), "0"); } TEST_CASE("bitwise_operators") {