diff options
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/event.h | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/events/event.h b/lib/events/event.h index 25362786..f985ae92 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -334,22 +334,18 @@ inline auto visit(const BaseEventT& event, FnT&& visitor) return visitor(event); } -template <typename T> -constexpr auto is_event() -{ - return std::is_base_of<Event, std::decay_t<T>>::value; -} - -template <typename T, typename FnT> -constexpr auto needs_cast() -{ - return !std::is_convertible<T, fn_arg_t<FnT>>::value; +namespace _impl { + template <typename T, typename FnT> + constexpr auto needs_downcast() + { + return !std::is_convertible_v<T, fn_arg_t<FnT>>; + } } // A single type-specific void visitor template <typename BaseEventT, typename FnT> -inline std::enable_if_t<is_event<BaseEventT>() && needs_cast<BaseEventT, FnT>() - && std::is_void<fn_return_t<FnT>>::value> +inline std::enable_if_t<_impl::needs_downcast<BaseEventT, FnT>() + && std::is_void_v<fn_return_t<FnT>>> visit(const BaseEventT& event, FnT&& visitor) { using event_type = fn_arg_t<FnT>; @@ -358,10 +354,9 @@ visit(const BaseEventT& event, FnT&& visitor) } // A single type-specific non-void visitor with an optional default value +// non-voidness is guarded by defaultValue type template <typename BaseEventT, typename FnT> -inline std::enable_if_t<is_event<BaseEventT>() && needs_cast<BaseEventT, FnT>(), - fn_return_t<FnT>> // non-voidness is guarded by - // defaultValue type +inline std::enable_if_t<_impl::needs_downcast<BaseEventT, FnT>(), fn_return_t<FnT>> visit(const BaseEventT& event, FnT&& visitor, fn_return_t<FnT>&& defaultValue = {}) { @@ -373,9 +368,8 @@ visit(const BaseEventT& event, FnT&& visitor, // A chain of 2 or more visitors template <typename BaseEventT, typename FnT1, typename FnT2, typename... FnTs> -inline std::enable_if_t<is_event<BaseEventT>(), fn_return_t<FnT1>> -visit(const BaseEventT& event, FnT1&& visitor1, FnT2&& visitor2, - FnTs&&... visitors) +inline fn_return_t<FnT1> visit(const BaseEventT& event, FnT1&& visitor1, + FnT2&& visitor2, FnTs&&... visitors) { using event_type1 = fn_arg_t<FnT1>; if (is<std::decay_t<event_type1>>(event)) |