From 18bb7ae1bdaf71d4b67730e8fda23d291c18d817 Mon Sep 17 00:00:00 2001 From: neargye Date: Thu, 2 May 2019 19:51:02 +0500 Subject: [PATCH] update readme --- README.md | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index d2319d6..d8bf865 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,6 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; // color_name -> "RED" ``` -* Static storage enum variable to string - ```cpp - constexpr Color color = Color::BLUE; - constexpr auto color_name = magic_enum::enum_name(color); - // color_name -> "BLUE" - ``` - * String to enum value ```cpp std::string color_name{"GREEN"}; @@ -72,14 +65,6 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; } ``` -* Static storage string to enum value - ```cpp - constexpr auto color = magic_enum::enum_cast("BLUE"); - if (color.has_value()) { - // color.value() -> Color::BLUE - } - ``` - * Integer to enum value ```cpp int color_integer = 2; @@ -89,14 +74,6 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; } ``` -* Static storage integer to enum value - ```cpp - constexpr auto color = magic_enum::enum_cast(4); - if (color.has_value()) { - // color.value() -> Color::BLUE - } - ``` - * Indexed access to enum value ```cpp int i = 1; @@ -178,6 +155,13 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; magic_enum::is_scoped_enum_v -> true ``` +* Static storage enum variable to string + ```cpp + constexpr Color color = Color::BLUE; + constexpr auto color_name = magic_enum::enum_name(); + // color_name -> "BLUE" + ``` + ## Remarks * `magic_enum::enum_cast` returns `std::optional`, using `has_value()` to check contains enum value and `value()` to get the enum value. @@ -188,6 +172,8 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; * `magic_enum::enum_name` returns `std::string_view`. If enum value does not have name, returns empty string. +* `magic_enum::enum_name()` is much lighter on the compile times and is not restricted to the enum_range limitation. + * `magic_enum::enum_names` returns `std::array` with all string enum name where `N = number of enum values`, sorted by enum value. * `magic_enum::enum_entries` returns `std::array, N>` with all std::pair (value enum, string enum name) where `N = number of enum values`, sorted by enum value.