From 3f0aad9f746381e71aab75d126ce9b3ac0a0b6cb Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 3 Oct 2019 00:02:39 -0700 Subject: [PATCH] Fix regression of enum_cast<>() when used with refs (EnumT& vs EnumT) (#16) --- include/magic_enum.hpp | 2 +- test/test.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 6280aa6..edf73c1 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -437,7 +437,7 @@ template // Obtains enum value from integer value. // Returns std::optional with enum value. template -[[nodiscard]] constexpr auto enum_cast(std::underlying_type_t value) noexcept -> detail::enable_if_enum_t>> { +[[nodiscard]] constexpr auto enum_cast(std::underlying_type_t> value) noexcept -> detail::enable_if_enum_t, std::optional>> { using D = std::decay_t; if (enum_traits::index(static_cast(value)) != -1) { diff --git a/test/test.cpp b/test/test.cpp index 1b8631b..49ce5dc 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -86,6 +86,7 @@ TEST_CASE("enum_cast") { constexpr auto cr = enum_cast(-12); REQUIRE(cr.value() == Color::RED); REQUIRE(enum_cast(7).value() == Color::GREEN); + REQUIRE(enum_cast(7).value() == Color::GREEN); REQUIRE(enum_cast((int)cm[2]).value() == Color::BLUE); REQUIRE_FALSE(enum_cast(0).has_value());