diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-08 10:56:25 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-08 10:58:25 +0900 |
commit | c4acd8ece12622164caf396c06bd0f22ab3589f7 (patch) | |
tree | 25aec38e1f451cbc2d0ddb0c959685d336bb16bd /lib/events | |
parent | f86f5272c27b4af1037045482135480a4bac3cd4 (diff) | |
download | libquotient-c4acd8ece12622164caf396c06bd0f22ab3589f7.tar.gz libquotient-c4acd8ece12622164caf396c06bd0f22ab3589f7.zip |
eventCast(): generalize to smart pointers
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> |