23 #define CATCH_CONFIG_MAIN
26 #define MAGIC_ENUM_USING_ALIAS_STRING_VIEW using string_view = std::wstring_view;
27 #define MAGIC_ENUM_USING_ALIAS_STRING using string = std::wstring;
33 #include <string_view>
49 static_assert(
is_magic_enum_supported,
"magic_enum: Unsupported compiler (https://github.com/Neargye/magic_enum#compiler-compatibility).");
53 constexpr
auto cr = enum_cast<Color>(L
"red");
56 REQUIRE(enum_cast<Color>(L
"blue", [](
wchar_t lhs,
wchar_t rhs) {
return std::tolower(lhs) == std::tolower(rhs); }).
value() ==
Color::BLUE);
62 constexpr
auto cr = enum_cast<Color>(-12);
71 REQUIRE(std::is_same_v<decltype(enum_values<Color>()),
const std::array<Color, 3>&>);
73 constexpr
auto&
s1 = enum_values<Color&>();
78 constexpr
auto s1 = enum_count<Color&>();
89 REQUIRE(enum_name<Color&>(cb) == L
"BLUE");
97 constexpr
auto cr_name = enum_name<cr>();
100 REQUIRE(enum_name<Color::BLUE>() == L
"BLUE");
106 REQUIRE(std::is_same_v<decltype(enum_names<Color>()),
const std::array<std::wstring_view, 3>&>);
108 constexpr
auto&
s1 = enum_names<Color&>();
109 REQUIRE(
s1 == std::array<std::wstring_view, 3>{{L
"red", L
"GREEN", L
"BLUE"}});
113 REQUIRE(std::is_same_v<decltype(enum_entries<Color>()),
const std::array<std::pair<Color, std::wstring_view>, 3>&>);
115 constexpr
auto&
s1 = enum_entries<Color&>();
120 auto test_ostream = [](
auto e, std::wstring name) {
122 std::wstringstream ss;
128 test_ostream(std::make_optional(
Color::RED), L
"red");
131 test_ostream(
static_cast<Color>(0), L
"0");
132 test_ostream(std::make_optional(
static_cast<Color>(0)), L
"0");
136 auto test_istream = [](
const auto e, std::wstring name) {
138 std::wistringstream ss(name);
139 std::decay_t<decltype(e)> v;