mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
Add enum fusing function (#127)
This commit is contained in:
parent
22242a613a
commit
1f8e29b140
4 changed files with 87 additions and 0 deletions
|
|
@ -1014,4 +1014,44 @@ TEST_CASE("constexpr_for") {
|
|||
});
|
||||
}
|
||||
|
||||
static int switch_case_2d(Color color, Directions number)
|
||||
{
|
||||
switch (magic_enum::enum_fuse(color, number))
|
||||
{
|
||||
case magic_enum::enum_fuse(Color::RED, Directions::Up):
|
||||
return 1;
|
||||
case magic_enum::enum_fuse(Color::BLUE, Directions::Down):
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
enum class Index { zero = 0, one = 1, two = 2 };
|
||||
|
||||
static int switch_case_3d(Color color, Directions number, Index index)
|
||||
{
|
||||
switch (magic_enum::enum_fuse(color, number, index))
|
||||
{
|
||||
case magic_enum::enum_fuse(Color::RED, Directions::Up, Index::zero):
|
||||
return 1;
|
||||
// model accidental removal of last index, must not match anything
|
||||
case magic_enum::enum_fuse(Color::BLUE, Directions::Up):
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("multdimensional-switch-case") {
|
||||
REQUIRE(switch_case_2d(Color::RED, Directions::Up) == 1);
|
||||
REQUIRE(switch_case_2d(Color::RED, Directions::Down) == 0);
|
||||
REQUIRE(switch_case_2d(Color::BLUE, Directions::Up) == 0);
|
||||
REQUIRE(switch_case_2d(Color::BLUE, Directions::Down) == 2);
|
||||
REQUIRE(switch_case_3d(Color::RED, Directions::Up, Index::zero) == 1);
|
||||
REQUIRE(switch_case_3d(Color::BLUE, Directions::Up, Index::zero) == 0);
|
||||
REQUIRE(switch_case_3d(Color::BLUE, Directions::Up, Index::one) == 0);
|
||||
REQUIRE(switch_case_3d(Color::BLUE, Directions::Up, Index::two) == 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue