From aa4ffe17c9501666be33a9cc6eed68c48bc76ba9 Mon Sep 17 00:00:00 2001 From: igormarkoff Date: Tue, 19 Mar 2019 15:51:05 +0300 Subject: [PATCH] Update EventEmitter.h Using from different projects in the same xcode workspace causes typeid returns different type_info for the same type (text name of the type is the same but its type_index is different). Since name is the same, using std::string as key of listeners map fixes the issue. One more change - I'm not sure whether this is a typo or not, but you use type (not Type) on line 52, I fixed this as well. If this is incorrect please revert. --- include/EventEmitter.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/EventEmitter.h b/include/EventEmitter.h index 151c2ef..47c78cb 100644 --- a/include/EventEmitter.h +++ b/include/EventEmitter.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace medooze { @@ -48,7 +49,7 @@ class EventEmitter template void emit(Type& type) { - auto it = listeners.find(typeid(type)); + auto it = listeners.find(typeid(Type).name()); if (it!=listeners.end()) static_cast*>(it->second.get())->emit(type); } @@ -56,11 +57,11 @@ class EventEmitter template EventEmitter& on(const std::function &callback) { - listeners[typeid(Type)] = std::unique_ptr(new Listener(callback)); + listeners[typeid(Type).name()] = std::unique_ptr(new Listener(callback)); return *this; } private: - std::map> listeners; + std::map> listeners; }; }; // namespace medooze