diff options
-rw-r--r-- | lib/events/event.h | 38 | ||||
-rw-r--r-- | lib/room.cpp | 4 |
2 files changed, 17 insertions, 25 deletions
diff --git a/lib/events/event.h b/lib/events/event.h index 12903274..7fd9868d 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -315,10 +315,11 @@ namespace QMatrixClient // A single type-specific void visitor template <typename BaseEventT, typename FnT> - inline auto visit(const BaseEventT& event, FnT&& visitor) - -> std::enable_if_t< - is_event_v<BaseEventT> && needs_cast_v<BaseEventT, FnT> && - std::is_void<fn_return_t<FnT>>::value> + inline + std::enable_if_t< + is_event_v<BaseEventT> && needs_cast_v<BaseEventT, FnT> && + std::is_void<fn_return_t<FnT>>::value> + visit(const BaseEventT& event, FnT&& visitor) { using event_type = fn_arg_t<FnT>; if (is<event_type>(event)) @@ -327,11 +328,12 @@ namespace QMatrixClient // A single type-specific non-void visitor with an optional default value template <typename BaseEventT, typename FnT> - inline auto visit(const BaseEventT& event, FnT&& visitor, - fn_return_t<FnT>&& defaultValue = {}) - -> std::enable_if_t< - is_event_v<BaseEventT> && needs_cast_v<BaseEventT, FnT>, - fn_return_t<FnT>> // non-voidness is guarded by defaultValue type + inline + std::enable_if_t< + is_event_v<BaseEventT> && needs_cast_v<BaseEventT, FnT>, + fn_return_t<FnT>> // non-voidness is guarded by defaultValue type + visit(const BaseEventT& event, FnT&& visitor, + fn_return_t<FnT>&& defaultValue = {}) { using event_type = fn_arg_t<FnT>; if (is<event_type>(event)) @@ -341,9 +343,10 @@ namespace QMatrixClient // A chain of 2 or more visitors template <typename BaseEventT, typename FnT1, typename FnT2, typename... FnTs> - inline auto visit(const BaseEventT& event, FnT1&& visitor1, - FnT2&& visitor2, FnTs&&... visitors) - -> std::enable_if_t<is_event_v<BaseEventT>, fn_return_t<FnT1>> + inline + std::enable_if_t<is_event_v<BaseEventT>, fn_return_t<FnT1>> + visit(const BaseEventT& event, FnT1&& visitor1, FnT2&& visitor2, + FnTs&&... visitors) { using event_type1 = fn_arg_t<FnT1>; if (is<event_type1>(event)) @@ -351,17 +354,6 @@ namespace QMatrixClient return visit(event, std::forward<FnT2>(visitor2), std::forward<FnTs>(visitors)...); } - - // An adaptor accepting a pointer-like object instead of an event - template <typename EventHolderT, typename... FnTs> - inline auto visit(const EventHolderT& e, FnTs&&... visitors) - -> decltype(visit(*e, std::forward<FnTs>(visitors)...)) - { - using return_type = decltype(visit(*e, std::forward<FnTs>(visitors)...)); - if (e) - return visit(*e, std::forward<FnTs>(visitors)...); - return return_type(); - } } // namespace QMatrixClient Q_DECLARE_METATYPE(QMatrixClient::Event*) Q_DECLARE_METATYPE(const QMatrixClient::Event*) diff --git a/lib/room.cpp b/lib/room.cpp index 080ad30d..dc9f5ccc 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1530,7 +1530,7 @@ bool Room::processStateEvent(const RoomEvent& e) void Room::processEphemeralEvent(EventPtr&& event) { QElapsedTimer et; et.start(); - visit(event + visit(*event , [this,et] (const TypingEvent& evt) { d->usersTyping.clear(); for( const QString& userId: qAsConst(evt.users()) ) @@ -1595,7 +1595,7 @@ void Room::processEphemeralEvent(EventPtr&& event) void Room::processAccountDataEvent(EventPtr&& event) { - visit(event + visit(*event , [this] (const TagEvent& evt) { auto newTags = evt.tags(); if (newTags == d->tags) |