From a23fa6df08008f4a3f7437efa8afe839a102dc8e Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 6 Jan 2019 17:43:37 +0900 Subject: visit(): pass decayed event types to is() So that is<> could be specialised for some types. --- lib/events/event.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/events/event.h b/lib/events/event.h index c51afcc4..d7ac4292 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -208,6 +208,9 @@ namespace QMatrixClient template inline auto registerEventType() { + // Initialise exactly once, even if this function is called twice for + // the same type (for whatever reason - you never know the ways of + // static initialisation is done). static const auto _ = setupFactory(); return _; // Only to facilitate usage in static initialisation } @@ -337,7 +340,8 @@ namespace QMatrixClient -> decltype(static_cast(&*eptr)) { Q_ASSERT(eptr); - return is(*eptr) ? static_cast(&*eptr) : nullptr; + return is>(*eptr) + ? static_cast(&*eptr) : nullptr; } // A single generic catch-all visitor @@ -369,7 +373,7 @@ namespace QMatrixClient visit(const BaseEventT& event, FnT&& visitor) { using event_type = fn_arg_t; - if (is(event)) + if (is>(event)) visitor(static_cast(event)); } @@ -383,7 +387,7 @@ namespace QMatrixClient fn_return_t&& defaultValue = {}) { using event_type = fn_arg_t; - if (is(event)) + if (is>(event)) return visitor(static_cast(event)); return std::forward>(defaultValue); } @@ -396,7 +400,7 @@ namespace QMatrixClient FnTs&&... visitors) { using event_type1 = fn_arg_t; - if (is(event)) + if (is>(event)) return visitor1(static_cast(event)); return visit(event, std::forward(visitor2), std::forward(visitors)...); -- cgit v1.2.3