diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-26 16:05:05 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-27 12:16:15 +0900 |
commit | cbf57ac2f5def2c2f54e07707120f8b224cdb093 (patch) | |
tree | 5172649a7873898bb3384f147c1764dc24b80f52 /lib/events/event.h | |
parent | 6ac825fe586b36c73abcadb6300a252c1da7b45a (diff) | |
download | libquotient-cbf57ac2f5def2c2f54e07707120f8b224cdb093.tar.gz libquotient-cbf57ac2f5def2c2f54e07707120f8b224cdb093.zip |
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.
Diffstat (limited to 'lib/events/event.h')
-rw-r--r-- | lib/events/event.h | 21 |
1 files changed, 7 insertions, 14 deletions
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<EventT>; template <typename EventT> - inline EventT* rawPtr(const event_ptr_tt<EventT>& ptr) + inline EventT* rawPtr(const event_ptr_tt<EventT>& ptr) // unwrap { return ptr.get(); } - template <typename TargetEventT, typename HolderT> - inline TargetEventT* weakPtrCast(const HolderT& ptr) + template <typename TargetEventT, typename EventT> + inline TargetEventT* weakPtrCast(const event_ptr_tt<EventT>& ptr) { return static_cast<TargetEventT*>(rawPtr(ptr)); } @@ -310,18 +310,11 @@ namespace QMatrixClient inline bool isUnknown(const Event& e) { return e.type() == unknownEventTypeId(); } - template <typename EventT, typename BaseEventT> - inline auto eventCast(BaseEventT& e) - -> Omittable<decltype(static_cast<EventT&>(e))> + template <typename EventT, typename BasePtrT> + inline auto eventCast(const BasePtrT& eptr) + -> decltype(static_cast<EventT*>(&*eptr)) { - return is<EventT>(e) ? static_cast<EventT&>(e) : none; - } - - template <typename EventT, typename HolderT> - inline auto eventCast(const HolderT& eptr) - -> decltype(static_cast<EventT*>(eptr.get())) - { - return is<EventT>(*eptr) ? static_cast<EventT*>(eptr.get()) : nullptr; + return is<EventT>(*eptr) ? static_cast<EventT*>(&*eptr) : nullptr; } // A single generic catch-all visitor |