From e429b61128b2bf6711bc825891752b7ede0a5835 Mon Sep 17 00:00:00 2001 From: neargye Date: Thu, 11 Jul 2019 20:23:32 +0500 Subject: [PATCH] update example --- example/example.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index c88cc46..c1f5a3c 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -24,7 +24,7 @@ #include -enum Color { RED = -10, BLUE = 0, GREEN = 10 }; +enum class Color : int { RED = -10, BLUE = 0, GREEN = 10 }; int main() { // Enum variable to string name. @@ -44,13 +44,13 @@ int main() { // String name to enum value. auto c2 = magic_enum::enum_cast("BLUE"); if (c2.has_value() && c2.value() == Color::BLUE) { - std::cout << "BLUE = " << c2.value() << std::endl; // BLUE = 0 + std::cout << "BLUE = " << static_cast(c2.value()) << std::endl; // BLUE = 0 } // Integer value to enum value. auto c3 = magic_enum::enum_cast(10); if (c3.has_value() && c3.value() == Color::GREEN) { - std::cout << "GREEN = " << c3.value() << std::endl; // GREEN = 10 + std::cout << "GREEN = " << magic_enum::enum_integer(c3.value()) << std::endl; // GREEN = 10 } // Enum value to integer value. @@ -83,12 +83,19 @@ int main() { // Checks whether type is an Unscoped enumeration. static_assert(magic_enum::is_unscoped_enum_v); + static_assert(!magic_enum::is_unscoped_enum_v); static_assert(!magic_enum::is_unscoped_enum_v); // Checks whether type is an Scoped enumeration. static_assert(!magic_enum::is_scoped_enum_v); + static_assert(magic_enum::is_scoped_enum_v); static_assert(magic_enum::is_scoped_enum_v); + // Checks whether type is an Fixed enumeration. + static_assert(!magic_enum::is_fixed_enum_v); + static_assert(magic_enum::is_fixed_enum_v); + static_assert(magic_enum::is_fixed_enum_v); + // Enum pair (value enum, string enum name) sequence. constexpr auto color_entries = magic_enum::enum_entries(); std::cout << "Colors entries:";