diff --git a/CMakeLists.txt b/CMakeLists.txt index 13d7514..a4efc7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.6) -project(magic_enum VERSION "0.2.0" LANGUAGES CXX) +project(magic_enum VERSION "0.3.0" LANGUAGES CXX) option(MAGIC_ENUM_OPT_BUILD_EXAMPLES "Build magic_enum examples" ON) option(MAGIC_ENUM_OPT_BUILD_TESTS "Build and perform magic_enum tests" ON) diff --git a/README.md b/README.md index f48bfea..b15a19d 100644 --- a/README.md +++ b/README.md @@ -16,17 +16,17 @@ [![Build Status](https://travis-ci.org/Neargye/magic_enum.svg?branch=master)](https://travis-ci.org/Neargye/magic_enum) [![Build status](https://ci.appveyor.com/api/projects/status/0rpr966p9ssrvwu3/branch/master?svg=true)](https://ci.appveyor.com/project/Neargye/magic-enum-hf8vk/branch/master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/64d04f150af14c3e8bd1090057b68538)](https://www.codacy.com/app/Neargye/magic_enum?utm_source=github.com&utm_medium=referral&utm_content=Neargye/magic_enum&utm_campaign=Badge_Grade) -[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/KOo6s4qJ9wUSxRGG) +[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/kXdow0AxI1Dss18p) ## What is Magic Enum? -Header-only C++17 library provides Enum-to-String and String-to-Enum and other useful functions, without any macro or boilerplate code. -* `magic_enum::enum_cast` obtains enum value from string or integer. -* `magic_enum::enum_value` obtains indexed access to enum value. -* `magic_enum::enum_values` obtains enum value sequence. -* `magic_enum::enum_count` obtains number of enum values. -* `magic_enum::enum_name` obtains string name from enum value. -* `magic_enum::enum_names` obtains string enum name sequence. +Header-only C++17 library provides Enum-to-String and String-to-Enum and other useful, functions work with any enum type without any macro or boilerplate code. +* `yae::enum_cast` obtains enum value from string or integer. +* `yae::enum_value` obtains indexed access to enum value. +* `yae::enum_values` obtains enum value sequence. +* `yae::enum_count` obtains number of enum values. +* `yae::enum_name` obtains string name from enum value. +* `yae::enum_names` obtains string enum name sequence. ## Features @@ -36,7 +36,8 @@ Header-only C++17 library provides Enum-to-String and String-to-Enum and other u * Compile-time * Enum to string * String to enum -* Works with any enum type +* Work with any enum type +* Without any macro or boilerplate code ## [Examples](example/example.cpp) @@ -48,7 +49,7 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; * Enum value to string ```cpp Color color = Color::RED; - auto color_name = magic_enum::enum_name(color); + auto color_name = yae::enum_name(color); if (color_name.has_value()) { // color_name.value() -> "RED" } @@ -57,7 +58,7 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; * Static storage enum variable to string ```cpp constexpr Color color = Color::BLUE; - constexpr auto color_name = magic_enum::enum_name(color); + constexpr auto color_name = yae::enum_name(color); if (color_name.has_value()) { // color_name.value() -> "BLUE" } @@ -66,7 +67,7 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; * String to enum value ```cpp std::string color_name{"GREEN"}; - auto color = magic_enum::enum_cast(color_name); + auto color = yae::enum_cast(color_name); if (color.has_value()) { // color.value() -> Color::GREEN } @@ -74,7 +75,7 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; * Static storage string to enum value ```cpp - constexpr auto color = magic_enum::enum_cast("BLUE"); + constexpr auto color = yae::enum_cast("BLUE"); if (color.has_value()) { // color.value() -> Color::BLUE } @@ -83,7 +84,7 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; * Integer to enum value ```cpp int color_value = 2; - auto color = magic_enum::enum_cast(color_value); + auto color = yae::enum_cast(color_value); if (colo.has_value()) { // color.value() -> Color::RED } @@ -91,7 +92,7 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; * Static storage integer to enum value ```cpp - constexpr auto color = magic_enum::enum_cast(4); + constexpr auto color = yae::enum_cast(4); if (color.has_value()) { // color.value() -> Color::BLUE } @@ -100,50 +101,50 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 }; * Indexed access to enum value ```cpp int i = 1; - Color colo = magic_enum::enum_value(i); + Color colo = yae::enum_value(i); // color -> Color::BLUE ``` * Compile-time indexed access. ```cpp - constexpr Color color = magic_enum::enum_value(0); + constexpr Color color = yae::enum_value(0); // color -> Color::RED ``` * Enum value sequence ```cpp - constexpr auto colors = magic_enum::enum_values(); + constexpr auto colors = yae::enum_values(); // colors -> {Color::RED, Color::BLUE, Color::GREEN} ``` * Number of enum elements ```cpp - constexpr std::size_t color_count = magic_enum::enum_count(); + constexpr std::size_t color_count = yae::enum_count(); // color_count -> 3 ``` * Enum names sequence ```cpp - constexpr auto color_names = magic_enum::enum_names(); + constexpr auto color_names = yae::enum_names(); // color_names -> {"RED", "BLUE", "GREEN"} ``` * Stream operator for enum ```cpp - using namespace magic_enum::ops; // out-of-the-box stream operator for enums. + using namespace yae::ops; // out-of-the-box stream operator for enums. Color color = Color::BLUE; std::cout << color << std::endl; // "BLUE" ``` ## Remarks -* `magic_enum::enum_cast` returns `std::optional`, using `has_value()` to check contains enum value and `value()` to get the enum value. +* `yae::enum_cast` returns `std::optional`, using `has_value()` to check contains enum value and `value()` to get the enum value. -* `magic_enum::enum_values` returns `std::array` with all enum value where `N = number of enum values`, sorted by enum value. +* `yae::enum_values` returns `std::array` with all enum value where `N = number of enum values`, sorted by enum value. -* `magic_enum::enum_name` returns `std::optional`, using `has_value()` to check contains enum name and `value()` to get the enum name. +* `yae::enum_name` returns `std::optional`, using `has_value()` to check contains enum name and `value()` to get the enum name. -* `magic_enum::enum_names` returns `std::array` with all string enum name where `N = number of enum values`, sorted by enum value. +* `yae::enum_names` returns `std::array` with all string enum name where `N = number of enum values`, sorted by enum value. * Enum value must be in range `(-MAGIC_ENUM_RANGE, MAGIC_ENUM_RANGE)`. By default `MAGIC_ENUM_RANGE = 256`. If you need a larger range, redefine the macro `MAGIC_ENUM_RANGE`. ```cpp diff --git a/example/example.cpp b/example/example.cpp index 07bf4ad..6dcefd9 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -29,13 +29,13 @@ enum Color { RED = -10, BLUE = 0, GREEN = 10 }; int main() { // Enum variable to string name. Color c1 = Color::RED; - auto c1_name = magic_enum::enum_name(c1); + auto c1_name = yae::enum_name(c1); if (c1_name.has_value()) { std::cout << c1_name.value() << std::endl; // RED } // String enum name sequence. - constexpr auto color_names = magic_enum::enum_names(); + constexpr auto color_names = yae::enum_names(); std::cout << "Color names:"; for (auto n : color_names) { std::cout << " " << n; @@ -44,29 +44,29 @@ int main() { // Color names: RED BLUE GREEN // String name to enum value. - auto c2 = magic_enum::enum_cast("BLUE"); + auto c2 = yae::enum_cast("BLUE"); if (c2.has_value() && c2.value() == Color::BLUE) { std::cout << "BLUE = " << c2.value() << std::endl; // BLUE = 0 } // Integer value to enum value. - auto c3 = magic_enum::enum_cast(10); + auto c3 = yae::enum_cast(10); if (c3.has_value() && c3.value() == Color::GREEN) { std::cout << "GREEN = " << c3.value() << std::endl; // GREEN = 10 } - using namespace magic_enum::ops; // out-of-the-box stream operator for enums. + using namespace yae::ops; // out-of-the-box stream operator for enums. // ostream operator for enum. std::cout << "Color: " << c1 << " " << c2 << " " << c3 << std::endl; // Color: RED BLUE GREEN // Number of enum values. - std::cout << "Color enum size: " << magic_enum::enum_count() << std::endl; // Color enum size: 3 + std::cout << "Color enum size: " << yae::enum_count() << std::endl; // Color enum size: 3 // Indexed access to enum value. - std::cout << "Color[0] = " << magic_enum::enum_value(0) << std::endl; // Color[0] = RED + std::cout << "Color[0] = " << yae::enum_value(0) << std::endl; // Color[0] = RED // Enum value sequence. - constexpr auto colors = magic_enum::enum_values(); + constexpr auto colors = yae::enum_values(); std::cout << "Colors sequence:"; for (Color c : colors) { std::cout << " " << c; // ostream operator for enum. diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index f5024ad..2459f9f 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -5,7 +5,7 @@ // | | | | (_| | (_| | | (__ | |____| | | | |_| | | | | | | | |____|_| |_| // |_| |_|\__,_|\__, |_|\___| |______|_| |_|\__,_|_| |_| |_| \_____| // __/ | https://github.com/Neargye/magic_enum -// |___/ vesion 0.3.0-dev +// |___/ vesion 0.3.0 // // Licensed under the MIT License . // SPDX-License-Identifier: MIT @@ -47,7 +47,7 @@ # define MAGIC_ENUM_RANGE 256 #endif -namespace magic_enum { +namespace yae { // aka Yet Another Enums. static_assert(MAGIC_ENUM_RANGE > 0, "MAGIC_ENUM_RANGE must be positive and greater than zero."); @@ -59,7 +59,7 @@ namespace detail { template struct enum_range final { using D = std::decay_t; - static_assert(std::is_enum_v, "magic_enum::detail::enum_range require enum type."); + static_assert(std::is_enum_v, "yae::detail::enum_range require enum type."); using U = std::underlying_type_t; using C = std::common_type_t; static constexpr int min = std::max(std::is_signed_v ? -MAGIC_ENUM_RANGE : 0, std::numeric_limits::min()); @@ -77,7 +77,7 @@ struct enum_range final { template [[nodiscard]] constexpr std::string_view name_impl() noexcept { - static_assert(std::is_enum_v, "magic_enum::detail::name_impl require enum type."); + static_assert(std::is_enum_v, "yae::detail::name_impl require enum type."); #if defined(__clang__) std::string_view name{__PRETTY_FUNCTION__}; constexpr auto suffix = sizeof("]") - 1; @@ -110,7 +110,7 @@ template template [[nodiscard]] constexpr decltype(auto) strings_impl(std::integer_sequence) noexcept { - static_assert(std::is_enum_v, "magic_enum::detail::strings_impl require enum type."); + static_assert(std::is_enum_v, "yae::detail::strings_impl require enum type."); constexpr std::array names{{name_impl(I + enum_range::min)>()...}}; return names; @@ -118,7 +118,7 @@ template template [[nodiscard]] constexpr std::string_view name_impl(int value) noexcept { - static_assert(std::is_enum_v, "magic_enum::detail::name_impl require enum type."); + static_assert(std::is_enum_v, "yae::detail::name_impl require enum type."); constexpr auto names = strings_impl(enum_range::sequence); return enum_range::contains(value) ? names[value - enum_range::min] : std::string_view{}; @@ -126,7 +126,7 @@ template template [[nodiscard]] constexpr decltype(auto) values_impl(std::integer_sequence) noexcept { - static_assert(std::is_enum_v, "magic_enum::detail::values_impl require enum type."); + static_assert(std::is_enum_v, "yae::detail::values_impl require enum type."); constexpr int n = sizeof...(I); constexpr std::array valid{{!name_impl(I + enum_range::min)>().empty()...}}; constexpr int num_valid = ((valid[I] ? 1 : 0) + ...); @@ -143,7 +143,7 @@ template template [[nodiscard]] constexpr decltype(auto) names_impl(std::integer_sequence) noexcept { - static_assert(std::is_enum_v, "magic_enum::detail::names_impl require enum type."); + static_assert(std::is_enum_v, "yae::detail::names_impl require enum type."); constexpr auto enums = values_impl(enum_range::sequence); constexpr std::array names{{name_impl()...}}; @@ -152,7 +152,7 @@ template template [[nodiscard]] constexpr std::optional enum_cast_impl(std::string_view value) noexcept { - static_assert(std::is_enum_v, "magic_enum::detail::enum_cast_impl require enum type."); + static_assert(std::is_enum_v, "yae::detail::enum_cast_impl require enum type."); constexpr auto values = values_impl(enum_range::sequence); constexpr auto count = values.size(); constexpr auto names = names_impl(std::make_index_sequence{}); @@ -169,7 +169,7 @@ template template using enable_if_enum_t = typename std::enable_if>>::type; -} // namespace magic_enum::detail +} // namespace yae::detail // Obtains enum value from enum string name. template > @@ -269,6 +269,6 @@ std::ostream& operator<<(std::ostream& os, std::optional value) { return os; } -} // namespace magic_enum::ops +} // namespace yae::ops -} // namespace magic_enum +} // namespace yae diff --git a/test/test.cpp b/test/test.cpp index ae43821..b772419 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -44,166 +44,166 @@ TEST_CASE("enum_cast") { # define constexpr // Visual Studio 2017 have bug with string_view constexpr compare. #endif - constexpr auto cr = magic_enum::enum_cast("RED"); + constexpr auto cr = yae::enum_cast("RED"); REQUIRE(cr.value() == Color::RED); - REQUIRE(magic_enum::enum_cast("GREEN").value() == Color::GREEN); - REQUIRE(magic_enum::enum_cast("BLUE").value() == Color::BLUE); - REQUIRE_FALSE(magic_enum::enum_cast("None").has_value()); + REQUIRE(yae::enum_cast("GREEN").value() == Color::GREEN); + REQUIRE(yae::enum_cast("BLUE").value() == Color::BLUE); + REQUIRE_FALSE(yae::enum_cast("None").has_value()); - constexpr auto no = magic_enum::enum_cast("one"); + constexpr auto no = yae::enum_cast("one"); REQUIRE(no.value() == Numbers::one); - REQUIRE(magic_enum::enum_cast("two").value() == Numbers::two); - REQUIRE(magic_enum::enum_cast("three").value() == Numbers::three); - REQUIRE_FALSE(magic_enum::enum_cast("None").has_value()); + REQUIRE(yae::enum_cast("two").value() == Numbers::two); + REQUIRE(yae::enum_cast("three").value() == Numbers::three); + REQUIRE_FALSE(yae::enum_cast("None").has_value()); - constexpr auto dr = magic_enum::enum_cast("Right"); - REQUIRE(magic_enum::enum_cast("Up").value() == Directions::Up); - REQUIRE(magic_enum::enum_cast("Down").value() == Directions::Down); + constexpr auto dr = yae::enum_cast("Right"); + REQUIRE(yae::enum_cast("Up").value() == Directions::Up); + REQUIRE(yae::enum_cast("Down").value() == Directions::Down); REQUIRE(dr.value() == Directions::Right); - REQUIRE(magic_enum::enum_cast("Left").value() == Directions::Left); - REQUIRE_FALSE(magic_enum::enum_cast("None").has_value()); + REQUIRE(yae::enum_cast("Left").value() == Directions::Left); + REQUIRE_FALSE(yae::enum_cast("None").has_value()); - constexpr auto nt = magic_enum::enum_cast("three"); - REQUIRE(magic_enum::enum_cast("one").value() == number::one); - REQUIRE(magic_enum::enum_cast("two").value() == number::two); + constexpr auto nt = yae::enum_cast("three"); + REQUIRE(yae::enum_cast("one").value() == number::one); + REQUIRE(yae::enum_cast("two").value() == number::two); REQUIRE(nt.value() == number::three); - REQUIRE_FALSE(magic_enum::enum_cast("None").has_value()); + REQUIRE_FALSE(yae::enum_cast("None").has_value()); #undef constexpr } SECTION("string") { - constexpr auto cr = magic_enum::enum_cast(-12); + constexpr auto cr = yae::enum_cast(-12); REQUIRE(cr.value() == Color::RED); - REQUIRE(magic_enum::enum_cast(7).value() == Color::GREEN); - REQUIRE(magic_enum::enum_cast(15).value() == Color::BLUE); - REQUIRE_FALSE(magic_enum::enum_cast(0).has_value()); + REQUIRE(yae::enum_cast(7).value() == Color::GREEN); + REQUIRE(yae::enum_cast(15).value() == Color::BLUE); + REQUIRE_FALSE(yae::enum_cast(0).has_value()); - constexpr auto no = magic_enum::enum_cast(10); + constexpr auto no = yae::enum_cast(10); REQUIRE(no.value() == Numbers::one); - REQUIRE(magic_enum::enum_cast(20).value() == Numbers::two); - REQUIRE(magic_enum::enum_cast(30).value() == Numbers::three); - REQUIRE_FALSE(magic_enum::enum_cast(0).has_value()); + REQUIRE(yae::enum_cast(20).value() == Numbers::two); + REQUIRE(yae::enum_cast(30).value() == Numbers::three); + REQUIRE_FALSE(yae::enum_cast(0).has_value()); - constexpr auto dr = magic_enum::enum_cast(119); - REQUIRE(magic_enum::enum_cast(85).value() == Directions::Up); - REQUIRE(magic_enum::enum_cast(-42).value() == Directions::Down); + constexpr auto dr = yae::enum_cast(119); + REQUIRE(yae::enum_cast(85).value() == Directions::Up); + REQUIRE(yae::enum_cast(-42).value() == Directions::Down); REQUIRE(dr.value() == Directions::Right); - REQUIRE(magic_enum::enum_cast(-119).value() == Directions::Left); - REQUIRE_FALSE(magic_enum::enum_cast(0).has_value()); + REQUIRE(yae::enum_cast(-119).value() == Directions::Left); + REQUIRE_FALSE(yae::enum_cast(0).has_value()); - constexpr auto nt = magic_enum::enum_cast(30); - REQUIRE(magic_enum::enum_cast(10).value() == number::one); - REQUIRE(magic_enum::enum_cast(20).value() == number::two); + constexpr auto nt = yae::enum_cast(30); + REQUIRE(yae::enum_cast(10).value() == number::one); + REQUIRE(yae::enum_cast(20).value() == number::two); REQUIRE(nt.value() == number::three); - REQUIRE_FALSE(magic_enum::enum_cast(0).has_value()); + REQUIRE_FALSE(yae::enum_cast(0).has_value()); } } TEST_CASE("enum_value") { - constexpr auto cr = magic_enum::enum_value(0); + constexpr auto cr = yae::enum_value(0); REQUIRE(cr == Color::RED); - REQUIRE(magic_enum::enum_value(1) == Color::GREEN); - REQUIRE(magic_enum::enum_value(2) == Color::BLUE); + REQUIRE(yae::enum_value(1) == Color::GREEN); + REQUIRE(yae::enum_value(2) == Color::BLUE); - constexpr auto no = magic_enum::enum_value(0); + constexpr auto no = yae::enum_value(0); REQUIRE(no == Numbers::one); - REQUIRE(magic_enum::enum_value(1) == Numbers::two); - REQUIRE(magic_enum::enum_value(2) == Numbers::three); + REQUIRE(yae::enum_value(1) == Numbers::two); + REQUIRE(yae::enum_value(2) == Numbers::three); - constexpr auto dr = magic_enum::enum_value(3); - REQUIRE(magic_enum::enum_value(0) == Directions::Left); - REQUIRE(magic_enum::enum_value(1) == Directions::Down); - REQUIRE(magic_enum::enum_value(2) == Directions::Up); + constexpr auto dr = yae::enum_value(3); + REQUIRE(yae::enum_value(0) == Directions::Left); + REQUIRE(yae::enum_value(1) == Directions::Down); + REQUIRE(yae::enum_value(2) == Directions::Up); REQUIRE(dr == Directions::Right); - constexpr auto nt = magic_enum::enum_value(2); - REQUIRE(magic_enum::enum_value(0) == number::one); - REQUIRE(magic_enum::enum_value(1) == number::two); + constexpr auto nt = yae::enum_value(2); + REQUIRE(yae::enum_value(0) == number::one); + REQUIRE(yae::enum_value(1) == number::two); REQUIRE(nt == number::three); } TEST_CASE("enum_values") { - constexpr auto mge_s1 = magic_enum::enum_values(); + constexpr auto mge_s1 = yae::enum_values(); REQUIRE(mge_s1 == std::array{Color::RED, Color::GREEN, Color::BLUE}); - constexpr auto mge_s2 = magic_enum::enum_values(); + constexpr auto mge_s2 = yae::enum_values(); REQUIRE(mge_s2 == std::array{Numbers::one, Numbers::two, Numbers::three}); - constexpr auto mge_s3 = magic_enum::enum_values(); + constexpr auto mge_s3 = yae::enum_values(); REQUIRE(mge_s3 == std::array{Directions::Left, Directions::Down, Directions::Up, Directions::Right}); - constexpr auto mge_s4 = magic_enum::enum_values(); + constexpr auto mge_s4 = yae::enum_values(); REQUIRE(mge_s4 == std::array{number::one, number::two, number::three}); } TEST_CASE("enum_count") { - constexpr auto mge_s1 = magic_enum::enum_count(); + constexpr auto mge_s1 = yae::enum_count(); REQUIRE(mge_s1 == 3); - constexpr auto mge_s2 = magic_enum::enum_count(); + constexpr auto mge_s2 = yae::enum_count(); REQUIRE(mge_s2 == 3); - constexpr auto mge_s3 = magic_enum::enum_count(); + constexpr auto mge_s3 = yae::enum_count(); REQUIRE(mge_s3 == 4); - constexpr auto mge_s4 = magic_enum::enum_count(); + constexpr auto mge_s4 = yae::enum_count(); REQUIRE(mge_s4 == 3); } TEST_CASE("enum_name") { constexpr Color cr = Color::RED; - constexpr auto cr_name = magic_enum::enum_name(cr); + constexpr auto cr_name = yae::enum_name(cr); Color cm[3] = {Color::RED, Color::GREEN, Color::BLUE}; REQUIRE(cr_name.value() == "RED"); - REQUIRE(magic_enum::enum_name(Color::BLUE).value() == "BLUE"); - REQUIRE(magic_enum::enum_name(cm[1]).value() == "GREEN"); - REQUIRE_FALSE(magic_enum::enum_name(static_cast(MAGIC_ENUM_RANGE)).has_value()); - REQUIRE_FALSE(magic_enum::enum_name(static_cast(-MAGIC_ENUM_RANGE)).has_value()); + REQUIRE(yae::enum_name(Color::BLUE).value() == "BLUE"); + REQUIRE(yae::enum_name(cm[1]).value() == "GREEN"); + REQUIRE_FALSE(yae::enum_name(static_cast(MAGIC_ENUM_RANGE)).has_value()); + REQUIRE_FALSE(yae::enum_name(static_cast(-MAGIC_ENUM_RANGE)).has_value()); constexpr Numbers no = Numbers::one; - constexpr auto no_name = magic_enum::enum_name(no); + constexpr auto no_name = yae::enum_name(no); REQUIRE(no_name.value() == "one"); - REQUIRE(magic_enum::enum_name(Numbers::two).value() == "two"); - REQUIRE(magic_enum::enum_name(Numbers::three).value() == "three"); - REQUIRE_FALSE(magic_enum::enum_name(static_cast(MAGIC_ENUM_RANGE)).has_value()); - REQUIRE_FALSE(magic_enum::enum_name(static_cast(-MAGIC_ENUM_RANGE)).has_value()); + REQUIRE(yae::enum_name(Numbers::two).value() == "two"); + REQUIRE(yae::enum_name(Numbers::three).value() == "three"); + REQUIRE_FALSE(yae::enum_name(static_cast(MAGIC_ENUM_RANGE)).has_value()); + REQUIRE_FALSE(yae::enum_name(static_cast(-MAGIC_ENUM_RANGE)).has_value()); constexpr Directions dr = Directions::Right; - constexpr auto dr_name = magic_enum::enum_name(dr); - REQUIRE(magic_enum::enum_name(Directions::Up).value() == "Up"); - REQUIRE(magic_enum::enum_name(Directions::Down).value() == "Down"); + constexpr auto dr_name = yae::enum_name(dr); + REQUIRE(yae::enum_name(Directions::Up).value() == "Up"); + REQUIRE(yae::enum_name(Directions::Down).value() == "Down"); REQUIRE(dr_name.value() == "Right"); - REQUIRE(magic_enum::enum_name(Directions::Left).value() == "Left"); - REQUIRE_FALSE(magic_enum::enum_name(static_cast(MAGIC_ENUM_RANGE)).has_value()); - REQUIRE_FALSE(magic_enum::enum_name(static_cast(-MAGIC_ENUM_RANGE)).has_value()); + REQUIRE(yae::enum_name(Directions::Left).value() == "Left"); + REQUIRE_FALSE(yae::enum_name(static_cast(MAGIC_ENUM_RANGE)).has_value()); + REQUIRE_FALSE(yae::enum_name(static_cast(-MAGIC_ENUM_RANGE)).has_value()); constexpr number nt = number::three; - constexpr auto nt_name = magic_enum::enum_name(nt); - REQUIRE(magic_enum::enum_name(number::one).value() == "one"); - REQUIRE(magic_enum::enum_name(number::two).value() == "two"); + constexpr auto nt_name = yae::enum_name(nt); + REQUIRE(yae::enum_name(number::one).value() == "one"); + REQUIRE(yae::enum_name(number::two).value() == "two"); REQUIRE(nt_name.value() == "three"); - REQUIRE_FALSE(magic_enum::enum_name(static_cast(MAGIC_ENUM_RANGE)).has_value()); - REQUIRE_FALSE(magic_enum::enum_name(static_cast(-MAGIC_ENUM_RANGE)).has_value()); + REQUIRE_FALSE(yae::enum_name(static_cast(MAGIC_ENUM_RANGE)).has_value()); + REQUIRE_FALSE(yae::enum_name(static_cast(-MAGIC_ENUM_RANGE)).has_value()); } TEST_CASE("enum_names") { - constexpr auto mge_s1 = magic_enum::enum_names(); + constexpr auto mge_s1 = yae::enum_names(); REQUIRE(mge_s1 == std::array{"RED", "GREEN", "BLUE"}); - constexpr auto mge_s2 = magic_enum::enum_names(); + constexpr auto mge_s2 = yae::enum_names(); REQUIRE(mge_s2 == std::array{"one", "two", "three"}); - constexpr auto mge_s3 = magic_enum::enum_names(); + constexpr auto mge_s3 = yae::enum_names(); REQUIRE(mge_s3 == std::array{"Left", "Down", "Up", "Right"}); - constexpr auto mge_s4 = magic_enum::enum_names(); + constexpr auto mge_s4 = yae::enum_names(); REQUIRE(mge_s4 == std::array{"one", "two", "three"}); } TEST_CASE("operator<<") { auto test_ostream = [](auto e, std::string_view name) { - using namespace magic_enum::ops; + using namespace yae::ops; std::stringstream ss; ss << e; REQUIRE(ss.str() == name);