24 #if defined(__clang__)
25 # pragma clang diagnostic push
26 #elif defined(__GNUC__)
27 # pragma GCC diagnostic push
28 #elif defined(_MSC_VER)
29 # pragma warning(push)
30 # pragma warning(disable : 4244) // warning C4244: 'argument': conversion from 'const T' to 'unsigned int', possible loss of data.
33 #define CATCH_CONFIG_MAIN
44 static constexpr
bool is_flags =
true;
55 [[nodiscard]] constexpr
bool empty() {
return std::equal_to{}(
r,
g) && std::equal_to{}(
g,
b) && std::equal_to{}(
b, 0); }
57 [[nodiscard]] constexpr
bool operator==(
RGB rgb)
const noexcept {
return std::equal_to{}(
r, rgb.r) && std::equal_to{}(
g, rgb.g) && std::equal_to{}(
b, rgb.b); }
61 ostream <<
"R=" <<
static_cast<std::uint32_t
>(rgb.
r) <<
" G=" <<
static_cast<std::uint32_t
>(rgb.
g) <<
" B=" <<
static_cast<std::uint32_t
>(rgb.
b);
66 template <
typename T>
bool check_const([[maybe_unused]]T& element) {
return false; }
67 template <
typename T>
bool check_const([[maybe_unused]]T
const& element) {
return true; }
69 constexpr std::uint8_t
color_max = std::numeric_limits<std::uint8_t>::max();
87 REQUIRE(color_rgb_container_int == compare_before);
89 constexpr
auto colors = magic_enum::enum_values<Color>();
91 std::ignore = magic_enum::containers::get<0>(compare_before);
92 std::ignore = magic_enum::containers::get<1>(compare_before);
93 std::ignore = magic_enum::containers::get<2>(compare_before);
95 std::ignore = magic_enum::containers::get<Color::RED>(compare_before);
96 std::ignore = magic_enum::containers::get<Color::GREEN>(compare_before);
97 std::ignore = magic_enum::containers::get<Color::BLUE>(compare_before);
99 REQUIRE(std::make_pair(colors[0], color_rgb_container_int[colors[0]]) == std::make_pair<Color, std::uint8_t>(
Color::RED, 1U));
100 REQUIRE(std::make_pair(colors[1], color_rgb_container_int[colors[1]]) == std::make_pair<Color, std::uint8_t>(
Color::GREEN, 4U));
101 REQUIRE(std::make_pair(colors[2], color_rgb_container_int[colors[2]]) == std::make_pair<Color, std::uint8_t>(
Color::BLUE, 2U));
103 std::sort(std::begin(color_rgb_container_int), std::end(color_rgb_container_int));
108 REQUIRE(color_rgb_container_int == compare_after);
110 std::ignore = magic_enum::containers::get<0>(compare_after);
111 std::ignore = magic_enum::containers::get<1>(compare_after);
112 std::ignore = magic_enum::containers::get<2>(compare_after);
114 std::ignore = magic_enum::containers::get<Color::RED>(compare_after);
115 std::ignore = magic_enum::containers::get<Color::GREEN>(compare_after);
116 std::ignore = magic_enum::containers::get<Color::BLUE>(compare_after);
118 REQUIRE(std::make_pair(colors[0], color_rgb_container_int[colors[0]]) == std::make_pair<Color, std::uint8_t>(
Color::RED, 1U));
119 REQUIRE(std::make_pair(colors[1], color_rgb_container_int[colors[1]]) == std::make_pair<Color, std::uint8_t>(
Color::GREEN, 2U));
120 REQUIRE(std::make_pair(colors[2], color_rgb_container_int[colors[2]]) == std::make_pair<Color, std::uint8_t>(
Color::BLUE, 4U));
124 REQUIRE(color_rgb_container.size() == 3);
125 REQUIRE(magic_enum::enum_count<Color>() == color_rgb_container.size());
140 REQUIRE(color_rgb_container.front() ==
RGB{color_max, 0, 0});
141 REQUIRE(color_rgb_container.back() ==
RGB{0, 0, color_max});
143 REQUIRE(magic_enum::containers::get<Color::RED>(color_rgb_container) ==
RGB{
color_max, 0, 0});
144 REQUIRE(magic_enum::containers::get<Color::GREEN>(color_rgb_container) ==
RGB{0,
color_max, 0});
145 REQUIRE(magic_enum::containers::get<Color::BLUE>(color_rgb_container) ==
RGB{0, 0,
color_max});
147 auto iterator = color_rgb_container.begin();
154 REQUIRE_FALSE(color_rgb_container == color_rgb_container_compare);
159 REQUIRE(color_rgb_container == color_rgb_container_compare);
161 constexpr
auto from_to_array = magic_enum::containers::to_array<Color, RGB>({{
color_max, 0, 0}, {0,
color_max, 0}, {0, 0,
color_max}});
172 REQUIRE(color_bitset.to_string().empty());
173 REQUIRE(color_bitset.size() == 3);
174 REQUIRE(magic_enum::enum_count<Color>() == color_bitset.size());
178 REQUIRE(color_bitset.count() == 0);
184 REQUIRE(color_bitset.count() == 1);
193 REQUIRE(color_bitset.count() == 2);
202 REQUIRE(color_bitset.count() == 3);
207 color_bitset.reset();
211 REQUIRE(color_bitset.count() == 0);
227 REQUIRE(color_bitset_all.to_string() ==
"RED|GREEN|BLUE");
228 REQUIRE(color_bitset_all.to_string( {},
'0',
'1' ) ==
"111");
229 REQUIRE(color_bitset_all.to_ulong( {} ) == 7);
230 REQUIRE(color_bitset_all.to_ullong( {} ) == 7);
231 REQUIRE(color_bitset_all.all());
232 REQUIRE(color_bitset_all.any());
236 REQUIRE(color_bitset_red_green.to_string() ==
"RED|GREEN");
237 REQUIRE(color_bitset_red_green.to_string( {},
'0',
'1' ) ==
"110");
238 REQUIRE(color_bitset_red_green.to_ulong( {} ) == 3);
239 REQUIRE(color_bitset_red_green.to_ullong( {} ) == 3);
241 REQUIRE(color_bitset_red_green.any());
252 REQUIRE(color_set.size() == 0);
253 REQUIRE_FALSE(magic_enum::enum_count<Color>() == color_set.size());
266 REQUIRE(color_set.size() == 3);
267 REQUIRE(magic_enum::enum_count<Color>() == color_set.size());
270 REQUIRE(magic_enum::enum_count<Color>() - 2 == color_set.size());
282 REQUIRE(color_set_filled.size() == 3);
283 REQUIRE(magic_enum::enum_count<Color>() == color_set_filled.size());
288 REQUIRE(magic_enum::enum_count<Color>() == color_set_not_const.
size());
289 color_set_not_const.
clear();
299 std::vector<std::pair<Color, RGB>>
map {{
Color::GREEN, {0,
color_max, 0}}, {
Color::BLUE, {0, 0,
color_max}}, {
Color::RED, {
color_max, 0, 0}}};
304 auto compare = [](std::pair<Color, RGB>& lhs,
305 std::pair<Color, RGB>& rhs) {
306 return static_cast<std::int32_t
>(lhs.first) <
static_cast<std::int32_t
>(rhs.first);
308 std::sort(std::begin(
map), std::end(
map), compare);