mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
add compile time enum_index (#159)
This commit is contained in:
parent
04a3d32d0f
commit
b0c0e02bdc
3 changed files with 56 additions and 28 deletions
|
|
@ -230,12 +230,14 @@ TEST_CASE("enum_index") {
|
|||
constexpr auto cr = enum_index(Color::RED);
|
||||
Color cg = Color::GREEN;
|
||||
REQUIRE(cr.value() == 0);
|
||||
REQUIRE(enum_index<Color::RED>() == 0);
|
||||
REQUIRE(enum_index<Color&>(cg).value() == 1);
|
||||
REQUIRE(enum_index(cm[2]).value() == 2);
|
||||
REQUIRE_FALSE(enum_index(static_cast<Color>(0)).has_value());
|
||||
|
||||
constexpr auto no = enum_index(Numbers::one);
|
||||
REQUIRE(no.value() == 0);
|
||||
REQUIRE(enum_index<Numbers::one>() == 0);
|
||||
REQUIRE(enum_index(Numbers::two).value() == 1);
|
||||
REQUIRE(enum_index(Numbers::three).value() == 2);
|
||||
REQUIRE_FALSE(enum_index(Numbers::many).has_value());
|
||||
|
|
@ -243,6 +245,7 @@ TEST_CASE("enum_index") {
|
|||
|
||||
constexpr auto dr = enum_index(Directions::Right);
|
||||
Directions dl = Directions::Left;
|
||||
REQUIRE(enum_index<Directions::Left>() == 0);
|
||||
REQUIRE(enum_index<Directions&>(dl).value() == 0);
|
||||
REQUIRE(enum_index<const Directions>(Directions::Down).value() == 1);
|
||||
REQUIRE(enum_index(Directions::Up).value() == 2);
|
||||
|
|
@ -260,6 +263,7 @@ TEST_CASE("enum_index") {
|
|||
#endif
|
||||
|
||||
constexpr auto nt = enum_index(number::three);
|
||||
REQUIRE(enum_index<number::one>() == 0);
|
||||
REQUIRE(enum_index(number::one).value() == 0);
|
||||
REQUIRE(enum_index(number::two).value() == 1);
|
||||
REQUIRE(nt.value() == 2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue