diff --git a/fairmq/EventManager.h b/fairmq/EventManager.h index 972db58e..43f3f267 100644 --- a/fairmq/EventManager.h +++ b/fairmq/EventManager.h @@ -32,7 +32,7 @@ namespace mq template struct Event { - using KeyType = const K; + using KeyType = K; }; /** @@ -53,16 +53,19 @@ struct Event class EventManager { public: - template - using Callback = std::function; + // Clang 3.4-3.8 has a bug and cannot properly deal with the following template alias. + // Therefore, we leave them here commented out for now. + // template + // using Callback = std::function; + template using Signal = boost::signals2::signal; template - auto Subscribe(const std::string& subscriber, Callback callback) -> void + auto Subscribe(const std::string& subscriber, std::function callback) -> void { const std::type_index event_type_index{typeid(E)}; - const std::type_index callback_type_index{typeid(Callback)}; + const std::type_index callback_type_index{typeid(std::function)}; const auto signalsKey = std::make_pair(event_type_index, callback_type_index); const auto connectionsKey = std::make_pair(subscriber, signalsKey); @@ -84,7 +87,7 @@ class EventManager auto Unsubscribe(const std::string& subscriber) -> void { const std::type_index event_type_index{typeid(E)}; - const std::type_index callback_type_index{typeid(Callback)}; + const std::type_index callback_type_index{typeid(std::function)}; const auto signalsKey = std::make_pair(event_type_index, callback_type_index); const auto connectionsKey = std::make_pair(subscriber, signalsKey); @@ -95,10 +98,10 @@ class EventManager } template - auto Emit(typename E::KeyType& key, Args... args) const -> void + auto Emit(typename E::KeyType key, Args... args) const -> void { const std::type_index event_type_index{typeid(E)}; - const std::type_index callback_type_index{typeid(Callback)}; + const std::type_index callback_type_index{typeid(std::function)}; const auto signalsKey = std::make_pair(event_type_index, callback_type_index); (*GetSignal(signalsKey))(key, std::forward(args)...); diff --git a/fairmq/StateMachine.h b/fairmq/StateMachine.h index ecc36e96..22a830c5 100644 --- a/fairmq/StateMachine.h +++ b/fairmq/StateMachine.h @@ -95,7 +95,7 @@ class StateMachine struct StateQueued : Event {}; auto SubscribeToStateChange(const std::string& subscriber, std::function callback) -> void { fCallbacks.Subscribe(subscriber, callback); } auto UnsubscribeFromStateChange(const std::string& subscriber) -> void { fCallbacks.Unsubscribe(subscriber); } - auto SubscribeToStateQueued(const std::string& subscriber, std::function callback) -> void { fCallbacks.Subscribe(subscriber, callback); } + auto SubscribeToStateQueued(const std::string& subscriber, std::function callback) -> void { fCallbacks.Subscribe(subscriber, callback); } auto UnsubscribeFromStateQueued(const std::string& subscriber) -> void { fCallbacks.Unsubscribe(subscriber); } auto GetCurrentState() const -> State { std::lock_guard lock{fMutex}; return fState; } diff --git a/fairmq/test/event_manager/_event_manager.cxx b/fairmq/test/event_manager/_event_manager.cxx index 1bdf2a9c..b765463b 100644 --- a/fairmq/test/event_manager/_event_manager.cxx +++ b/fairmq/test/event_manager/_event_manager.cxx @@ -16,7 +16,7 @@ namespace using namespace std; using namespace fair::mq; -struct TestEvent : fair::mq::Event {}; +struct TestEvent : fair::mq::Event {}; TEST(EventManager, Basics) { @@ -26,14 +26,14 @@ TEST(EventManager, Basics) int value = 0; string value2; - EventManager::Callback callback{ - [&](TestEvent::KeyType& key, int newValue){ + std::function callback{ + [&](TestEvent::KeyType key, int newValue){ ++call_counter; if (key == "test") value = newValue; } }; - EventManager::Callback callback2{ - [&](TestEvent::KeyType& key, string newValue){ + std::function callback2{ + [&](TestEvent::KeyType key, string newValue){ ++call_counter2; if (key == "test") value2 = newValue; }