From 0bfcf63e459e0cb4242d65acaf6e689f40c41ae3 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 8 Jul 2018 14:29:29 +0900 Subject: visit<>(): drop the overload for pointer-like objects It confuses compilers and adds a mostly unneeded null check; it's dead easy to just dereference a pointer before passing it to visit<>(). --- lib/events/event.h | 38 +++++++++++++++----------------------- lib/room.cpp | 4 ++-- 2 files changed, 17 insertions(+), 25 deletions(-) (limited to 'lib') 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 - inline auto visit(const BaseEventT& event, FnT&& visitor) - -> std::enable_if_t< - is_event_v && needs_cast_v && - std::is_void>::value> + inline + std::enable_if_t< + is_event_v && needs_cast_v && + std::is_void>::value> + visit(const BaseEventT& event, FnT&& visitor) { using event_type = fn_arg_t; if (is(event)) @@ -327,11 +328,12 @@ namespace QMatrixClient // A single type-specific non-void visitor with an optional default value template - inline auto visit(const BaseEventT& event, FnT&& visitor, - fn_return_t&& defaultValue = {}) - -> std::enable_if_t< - is_event_v && needs_cast_v, - fn_return_t> // non-voidness is guarded by defaultValue type + inline + std::enable_if_t< + is_event_v && needs_cast_v, + fn_return_t> // non-voidness is guarded by defaultValue type + visit(const BaseEventT& event, FnT&& visitor, + fn_return_t&& defaultValue = {}) { using event_type = fn_arg_t; if (is(event)) @@ -341,9 +343,10 @@ namespace QMatrixClient // A chain of 2 or more visitors template - inline auto visit(const BaseEventT& event, FnT1&& visitor1, - FnT2&& visitor2, FnTs&&... visitors) - -> std::enable_if_t, fn_return_t> + inline + std::enable_if_t, fn_return_t> + visit(const BaseEventT& event, FnT1&& visitor1, FnT2&& visitor2, + FnTs&&... visitors) { using event_type1 = fn_arg_t; if (is(event)) @@ -351,17 +354,6 @@ namespace QMatrixClient return visit(event, std::forward(visitor2), std::forward(visitors)...); } - - // An adaptor accepting a pointer-like object instead of an event - template - inline auto visit(const EventHolderT& e, FnTs&&... visitors) - -> decltype(visit(*e, std::forward(visitors)...)) - { - using return_type = decltype(visit(*e, std::forward(visitors)...)); - if (e) - return visit(*e, std::forward(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) -- cgit v1.2.3