diff options
author | Black Hat <bhat@encom.eu.org> | 2019-09-30 21:38:00 -0700 |
---|---|---|
committer | Black Hat <bhat@encom.eu.org> | 2019-09-30 21:38:00 -0700 |
commit | 3e694fc4c85920d897979f955901cfd93dfba562 (patch) | |
tree | d9b2a84259ec6a41b6ecdc4d02d2c87a52794c1a /lib/events | |
parent | 6870ee0d7a0df3427845de07ddae1e2fd5768bbb (diff) | |
parent | f71d16b56ab90e494d6a41c276210a4ce593987e (diff) | |
download | libquotient-3e694fc4c85920d897979f955901cfd93dfba562.tar.gz libquotient-3e694fc4c85920d897979f955901cfd93dfba562.zip |
Merge branch 'master' of https://github.com/quotient-im/libQuotient into bhat-libqtolm-update
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)) |