From a733a2ea665ca5d72b7270f0334bf2e7b82bd0cc Mon Sep 17 00:00:00 2001 From: neargye Date: Wed, 11 Jun 2025 21:39:34 +0400 Subject: [PATCH] clean-up --- include/magic_enum/magic_enum.hpp | 22 +++++++++------------- include/magic_enum/magic_enum_flags.hpp | 4 ++-- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/magic_enum/magic_enum.hpp b/include/magic_enum/magic_enum.hpp index b6cd61e..6a37caf 100644 --- a/include/magic_enum/magic_enum.hpp +++ b/include/magic_enum/magic_enum.hpp @@ -374,19 +374,15 @@ constexpr std::size_t find(string_view str, char_type c) noexcept { } template -constexpr bool is_default_predicate() noexcept { - return std::is_same_v, std::equal_to> || - std::is_same_v, std::equal_to<>>; -} +inline constexpr bool is_default_predicate_v = std::is_same_v, std::equal_to> || std::is_same_v, std::equal_to<>>; + template -constexpr bool is_nothrow_invocable() { - return is_default_predicate() || - std::is_nothrow_invocable_r_v; -} +inline constexpr bool is_nothrow_invocable_v = is_default_predicate_v || std::is_nothrow_invocable_r_v; + template -constexpr bool cmp_equal(string_view lhs, string_view rhs, [[maybe_unused]] BinaryPredicate&& p) noexcept(is_nothrow_invocable()) { +constexpr bool cmp_equal(string_view lhs, string_view rhs, [[maybe_unused]] BinaryPredicate&& p) noexcept(is_nothrow_invocable_v) { #if defined(_MSC_VER) && _MSC_VER < 1920 && !defined(__clang__) // https://developercommunity.visualstudio.com/content/problem/360432/vs20178-regression-c-failed-in-test.html // https://developercommunity.visualstudio.com/content/problem/232218/c-constexpr-string-view.html @@ -395,7 +391,7 @@ constexpr bool cmp_equal(string_view lhs, string_view rhs, [[maybe_unused]] Bina constexpr bool workaround = false; #endif - if constexpr (!is_default_predicate() || workaround) { + if constexpr (!is_default_predicate_v || workaround) { if (lhs.size() != rhs.size()) { return false; } @@ -1412,12 +1408,12 @@ template > // Obtains enum value from name. // Returns optional with enum value. template , typename BinaryPredicate = std::equal_to<>> -[[nodiscard]] constexpr auto enum_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable()) -> detail::enable_if_t>, BinaryPredicate> { +[[nodiscard]] constexpr auto enum_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable_v) -> detail::enable_if_t>, BinaryPredicate> { using D = std::decay_t; static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); #if defined(MAGIC_ENUM_ENABLE_HASH) - if constexpr (detail::is_default_predicate()) { + if constexpr (detail::is_default_predicate_v) { return detail::constexpr_switch<&detail::names_v, detail::case_call_t::index>( [](std::size_t i) { return optional{detail::values_v[i]}; }, value, @@ -1461,7 +1457,7 @@ template > // Checks whether enum contains enumerator with such name. template , typename BinaryPredicate = std::equal_to<>> -[[nodiscard]] constexpr auto enum_contains(string_view value, BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable()) -> detail::enable_if_t { +[[nodiscard]] constexpr auto enum_contains(string_view value, BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable_v) -> detail::enable_if_t { using D = std::decay_t; return static_cast(enum_cast(value, std::move(p))); diff --git a/include/magic_enum/magic_enum_flags.hpp b/include/magic_enum/magic_enum_flags.hpp index f2d81b5..54a5507 100644 --- a/include/magic_enum/magic_enum_flags.hpp +++ b/include/magic_enum/magic_enum_flags.hpp @@ -131,7 +131,7 @@ template // Obtains enum-flags value from name. // Returns optional with enum-flags value. template > -[[nodiscard]] constexpr auto enum_flags_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable()) -> detail::enable_if_t>, BinaryPredicate> { +[[nodiscard]] constexpr auto enum_flags_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable_v) -> detail::enable_if_t>, BinaryPredicate> { using D = std::decay_t; using U = underlying_type_t; constexpr auto S = detail::enum_subtype::flags; @@ -185,7 +185,7 @@ template // Checks whether enum-flags contains enumerator with such name. template > -[[nodiscard]] constexpr auto enum_flags_contains(string_view value, BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable()) -> detail::enable_if_t { +[[nodiscard]] constexpr auto enum_flags_contains(string_view value, BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable_v) -> detail::enable_if_t { using D = std::decay_t; return static_cast(enum_flags_cast(value, std::move(p)));