diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-09-29 18:03:31 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-09-29 23:35:51 +0900 |
commit | 72dd1eb7c1986c23a7630205e2f2a0280b7c2a2b (patch) | |
tree | 10cf5df3576b8ef821281531ed136302d630a738 | |
parent | 36589cd6e4c557da7d694c5973546f29a09dee7c (diff) | |
download | libquotient-72dd1eb7c1986c23a7630205e2f2a0280b7c2a2b.tar.gz libquotient-72dd1eb7c1986c23a7630205e2f2a0280b7c2a2b.zip |
Simplify visit() signature
Checking that BaseEventT descends from Event is really extraneous.
-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)) |