Skip to content

Commit

Permalink
fix enum_reflected
Browse files Browse the repository at this point in the history
  • Loading branch information
Neargye committed Jun 29, 2024
1 parent bc2e948 commit f08355c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions include/magic_enum/magic_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,33 +1414,34 @@ template <typename E, detail::enum_subtype S = detail::subtype_v<E>, typename Bi
return static_cast<bool>(enum_cast<D, S>(value, std::move(p)));
}

// Returns true if the enum value is in the range of values that can be reflected.
// Returns true if the enum integer value is in the range of values that can be reflected.
template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
[[nodiscard]] constexpr auto enum_reflected(E value) noexcept -> detail::enable_if_t<E, bool> {
[[nodiscard]] constexpr auto enum_reflected(underlying_type_t<E> value) noexcept -> detail::enable_if_t<E, bool> {
using D = std::decay_t<E>;

if constexpr (detail::is_reflected_v<D, S>) {
constexpr auto min = detail::reflected_min<E, S>();
constexpr auto max = detail::reflected_max<E, S>();
return value >= min && value <= max;
} else {
return false;
}
return false;
}

// Returns true if the enum value is in the range of values that can be reflected.
template <detail::enum_subtype S, typename E>
template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
[[nodiscard]] constexpr auto enum_reflected(E value) noexcept -> detail::enable_if_t<E, bool> {
using D = std::decay_t<E>;

return enum_cast<D, S>(value);
return enum_reflected<D, S>(static_cast<underlying_type_t<D>>(value));
}

// Returns true if the enum integer value is in the range of values that can be reflected.
template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
[[nodiscard]] constexpr auto enum_reflected(underlying_type_t<E> value) noexcept -> detail::enable_if_t<E, bool> {
// Returns true if the enum value is in the range of values that can be reflected.
template <detail::enum_subtype S, typename E>
[[nodiscard]] constexpr auto enum_reflected(E value) noexcept -> detail::enable_if_t<E, bool> {
using D = std::decay_t<E>;

return enum_cast<D, S>(value);
return enum_reflected<D, S>(value);
}

template <bool AsFlags = true>
Expand Down

0 comments on commit f08355c

Please sign in to comment.