Skip to content

Commit

Permalink
fix Argument-dependent lookup results in enum_switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Neargye committed Oct 4, 2023
1 parent dfcd851 commit d67973d
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions include/magic_enum_switch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,13 @@ inline constexpr auto default_result_type_lambda = []() noexcept(std::is_nothrow
template <>
inline constexpr auto default_result_type_lambda<void> = []() noexcept {};

template <typename R, typename F, typename... Args>
constexpr R invoke_r(F&& f, Args&&... args) noexcept(std::is_nothrow_invocable_r_v<R, F, Args...>) {
if constexpr (std::is_void_v<R>) {
std::forward<F>(f)(std::forward<Args>(args)...);
} else {
return static_cast<R>(std::forward<F>(f)(std::forward<Args>(args)...));
}
}

template <std::size_t I, std::size_t End, typename R, typename E, enum_subtype S, typename F, typename Def>
constexpr decltype(auto) constexpr_switch_impl(F&& f, E value, Def&& def) {
if constexpr(I < End) {
constexpr auto v = enum_constant<enum_value<E, I, S>()>{};
if (value == v) {
if constexpr (std::is_invocable_r_v<R, F, decltype(v)>) {
return invoke_r<R>(std::forward<F>(f), v);
return static_cast<R>(std::forward<F>(f)(v));
} else {
return def();
}
Expand Down

0 comments on commit d67973d

Please sign in to comment.