MCPcopy Create free account
hub / github.com/Neargye/magic_enum / constexpr_switch_impl

Function constexpr_switch_impl

include/magic_enum/magic_enum_switch.hpp:105–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103
104template <std::size_t I, std::size_t End, typename R, typename E, enum_subtype S, typename F, typename Def>
105constexpr decltype(auto) constexpr_switch_impl(F&& f, E value, Def&& def) {
106 if constexpr(I < End) {
107 constexpr auto v = enum_constant<enum_value<E, I, S>()>{};
108 if (value == v) {
109 if constexpr (std::is_invocable_r_v<R, F, decltype(v)>) {
110 return static_cast<R>(std::forward<F>(f)(v));
111 } else {
112 return def();
113 }
114 } else {
115 return constexpr_switch_impl<I + 1, End, R, E, S>(std::forward<F>(f), value, std::forward<Def>(def));
116 }
117 } else {
118 return def();
119 }
120}
121
122template <typename R, typename E, enum_subtype S, typename F, typename Def>
123constexpr decltype(auto) constexpr_switch(F&& f, E value, Def&& def) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected