From cbf57ac2f5def2c2f54e07707120f8b224cdb093 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 26 Jul 2018 16:05:05 +0900 Subject: event.h: drop eventCast for references; other cleanup Omittable<> doesn't work with reference types and returning an unknown event spoils the experience. It's much simpler to just deal with event pointers instead. --- lib/events/event.h | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'lib/events/event.h') diff --git a/lib/events/event.h b/lib/events/event.h index 8757ba53..2e763bb8 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -35,13 +35,13 @@ namespace QMatrixClient using event_ptr_tt = std::unique_ptr; template - inline EventT* rawPtr(const event_ptr_tt& ptr) + inline EventT* rawPtr(const event_ptr_tt& ptr) // unwrap { return ptr.get(); } - template - inline TargetEventT* weakPtrCast(const HolderT& ptr) + template + inline TargetEventT* weakPtrCast(const event_ptr_tt& ptr) { return static_cast(rawPtr(ptr)); } @@ -310,18 +310,11 @@ namespace QMatrixClient inline bool isUnknown(const Event& e) { return e.type() == unknownEventTypeId(); } - template - inline auto eventCast(BaseEventT& e) - -> Omittable(e))> + template + inline auto eventCast(const BasePtrT& eptr) + -> decltype(static_cast(&*eptr)) { - return is(e) ? static_cast(e) : none; - } - - template - inline auto eventCast(const HolderT& eptr) - -> decltype(static_cast(eptr.get())) - { - return is(*eptr) ? static_cast(eptr.get()) : nullptr; + return is(*eptr) ? static_cast(&*eptr) : nullptr; } // A single generic catch-all visitor -- cgit v1.2.3