Skip to content

Commit a733a2e

Browse files
committed
clean-up
1 parent d642b05 commit a733a2e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

include/magic_enum/magic_enum.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,15 @@ constexpr std::size_t find(string_view str, char_type c) noexcept {
374374
}
375375

376376
template <typename BinaryPredicate>
377-
constexpr bool is_default_predicate() noexcept {
378-
return std::is_same_v<std::decay_t<BinaryPredicate>, std::equal_to<string_view::value_type>> ||
379-
std::is_same_v<std::decay_t<BinaryPredicate>, std::equal_to<>>;
380-
}
377+
inline constexpr bool is_default_predicate_v = std::is_same_v<std::decay_t<BinaryPredicate>, std::equal_to<string_view::value_type>> || std::is_same_v<std::decay_t<BinaryPredicate>, std::equal_to<>>;
378+
381379

382380
template <typename BinaryPredicate>
383-
constexpr bool is_nothrow_invocable() {
384-
return is_default_predicate<BinaryPredicate>() ||
385-
std::is_nothrow_invocable_r_v<bool, BinaryPredicate, char_type, char_type>;
386-
}
381+
inline constexpr bool is_nothrow_invocable_v = is_default_predicate_v<BinaryPredicate> || std::is_nothrow_invocable_r_v<bool, BinaryPredicate, char_type, char_type>;
382+
387383

388384
template <typename BinaryPredicate>
389-
constexpr bool cmp_equal(string_view lhs, string_view rhs, [[maybe_unused]] BinaryPredicate&& p) noexcept(is_nothrow_invocable<BinaryPredicate>()) {
385+
constexpr bool cmp_equal(string_view lhs, string_view rhs, [[maybe_unused]] BinaryPredicate&& p) noexcept(is_nothrow_invocable_v<BinaryPredicate>) {
390386
#if defined(_MSC_VER) && _MSC_VER < 1920 && !defined(__clang__)
391387
// https://developercommunity.visualstudio.com/content/problem/360432/vs20178-regression-c-failed-in-test.html
392388
// 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
395391
constexpr bool workaround = false;
396392
#endif
397393

398-
if constexpr (!is_default_predicate<BinaryPredicate>() || workaround) {
394+
if constexpr (!is_default_predicate_v<BinaryPredicate> || workaround) {
399395
if (lhs.size() != rhs.size()) {
400396
return false;
401397
}
@@ -1412,12 +1408,12 @@ template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
14121408
// Obtains enum value from name.
14131409
// Returns optional with enum value.
14141410
template <typename E, detail::enum_subtype S = detail::subtype_v<E>, typename BinaryPredicate = std::equal_to<>>
1415-
[[nodiscard]] constexpr auto enum_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable<BinaryPredicate>()) -> detail::enable_if_t<E, optional<std::decay_t<E>>, BinaryPredicate> {
1411+
[[nodiscard]] constexpr auto enum_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable_v<BinaryPredicate>) -> detail::enable_if_t<E, optional<std::decay_t<E>>, BinaryPredicate> {
14161412
using D = std::decay_t<E>;
14171413
static_assert(detail::is_reflected_v<D, S>, "magic_enum requires enum implementation and valid max and min.");
14181414

14191415
#if defined(MAGIC_ENUM_ENABLE_HASH)
1420-
if constexpr (detail::is_default_predicate<BinaryPredicate>()) {
1416+
if constexpr (detail::is_default_predicate_v<BinaryPredicate>) {
14211417
return detail::constexpr_switch<&detail::names_v<D, S>, detail::case_call_t::index>(
14221418
[](std::size_t i) { return optional<D>{detail::values_v<D, S>[i]}; },
14231419
value,
@@ -1461,7 +1457,7 @@ template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
14611457

14621458
// Checks whether enum contains enumerator with such name.
14631459
template <typename E, detail::enum_subtype S = detail::subtype_v<E>, typename BinaryPredicate = std::equal_to<>>
1464-
[[nodiscard]] constexpr auto enum_contains(string_view value, BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable<BinaryPredicate>()) -> detail::enable_if_t<E, bool, BinaryPredicate> {
1460+
[[nodiscard]] constexpr auto enum_contains(string_view value, BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable_v<BinaryPredicate>) -> detail::enable_if_t<E, bool, BinaryPredicate> {
14651461
using D = std::decay_t<E>;
14661462

14671463
return static_cast<bool>(enum_cast<D, S>(value, std::move(p)));

include/magic_enum/magic_enum_flags.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ template <typename E>
131131
// Obtains enum-flags value from name.
132132
// Returns optional with enum-flags value.
133133
template <typename E, typename BinaryPredicate = std::equal_to<>>
134-
[[nodiscard]] constexpr auto enum_flags_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable<BinaryPredicate>()) -> detail::enable_if_t<E, optional<std::decay_t<E>>, BinaryPredicate> {
134+
[[nodiscard]] constexpr auto enum_flags_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable_v<BinaryPredicate>) -> detail::enable_if_t<E, optional<std::decay_t<E>>, BinaryPredicate> {
135135
using D = std::decay_t<E>;
136136
using U = underlying_type_t<D>;
137137
constexpr auto S = detail::enum_subtype::flags;
@@ -185,7 +185,7 @@ template <typename E>
185185

186186
// Checks whether enum-flags contains enumerator with such name.
187187
template <typename E, typename BinaryPredicate = std::equal_to<>>
188-
[[nodiscard]] constexpr auto enum_flags_contains(string_view value, BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable<BinaryPredicate>()) -> detail::enable_if_t<E, bool, BinaryPredicate> {
188+
[[nodiscard]] constexpr auto enum_flags_contains(string_view value, BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable_v<BinaryPredicate>) -> detail::enable_if_t<E, bool, BinaryPredicate> {
189189
using D = std::decay_t<E>;
190190

191191
return static_cast<bool>(enum_flags_cast<D>(value, std::move(p)));

0 commit comments

Comments
 (0)