diff options
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/event.h | 16 |
1 files changed, 7 insertions, 9 deletions
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 <typename EventT, typename BaseEventT> - inline Omittable<EventT> eventCast(BaseEventT&& e) + inline auto eventCast(BaseEventT& e) + -> Omittable<decltype(static_cast<EventT&>(e))> { - if (is<EventT>(e)) - return static_cast<EventT>(e); - return none; + return is<EventT>(e) ? static_cast<EventT&>(e) : none; } - template <typename EventT, typename PtrT> - inline EventT* eventCast(PtrT* eptr) + template <typename EventT, typename HolderT> + inline auto eventCast(const HolderT& eptr) + -> decltype(static_cast<EventT*>(eptr.get())) { - if (is<EventT>(*eptr)) - return static_cast<EventT*>(eptr); - return {}; + return is<EventT>(*eptr) ? static_cast<EventT*>(eptr.get()) : nullptr; } template <typename BaseEventT, typename FnT, typename DefaultT> |