From c4acd8ece12622164caf396c06bd0f22ab3589f7 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 8 Jul 2018 10:56:25 +0900 Subject: eventCast(): generalize to smart pointers --- lib/events/event.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/events/event.h') diff --git a/lib/events/event.h b/lib/events/event.h index b188a40b..2ba95b63 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -286,19 +286,17 @@ namespace QMatrixClient inline bool isUnknown(const Event& e) { return e.type() == unknownEventTypeId(); } template - inline Omittable eventCast(BaseEventT&& e) + inline auto eventCast(BaseEventT& e) + -> Omittable(e))> { - if (is(e)) - return static_cast(e); - return none; + return is(e) ? static_cast(e) : none; } - template - inline EventT* eventCast(PtrT* eptr) + template + inline auto eventCast(const HolderT& eptr) + -> decltype(static_cast(eptr.get())) { - if (is(*eptr)) - return static_cast(eptr); - return {}; + return is(*eptr) ? static_cast(eptr.get()) : nullptr; } template -- cgit v1.2.3