mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
clean-up ostream operator
This commit is contained in:
parent
f5ef718120
commit
777792339c
2 changed files with 9 additions and 11 deletions
|
|
@ -394,13 +394,7 @@ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& o
|
|||
static_assert(detail::check_enum_v<E, D>, "magic_enum::ostream_operators::operator<< requires enum type.");
|
||||
|
||||
if (value.has_value()) {
|
||||
if (auto name = detail::name_impl<D>(value.value()); !name.empty()) {
|
||||
for (auto c : name) {
|
||||
os.put(c);
|
||||
}
|
||||
} else {
|
||||
os << static_cast<std::underlying_type_t<D>>(value.value());
|
||||
}
|
||||
os << value.value();
|
||||
}
|
||||
|
||||
return os;
|
||||
|
|
|
|||
|
|
@ -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<Color>(0), "0");
|
||||
test_ostream(std::make_optional(static_cast<Color>(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<Numbers>(0), "0");
|
||||
test_ostream(std::make_optional(static_cast<Numbers>(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<Directions>(0), "0");
|
||||
test_ostream(std::make_optional(static_cast<Directions>(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<number>(0), "0");
|
||||
test_ostream(std::make_optional(static_cast<number>(0)), "0");
|
||||
}
|
||||
|
||||
TEST_CASE("bitwise_operators") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue