X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/ee1709cd231588fe672d0bd2546ef69ee87ff88c..b2b89723a2427bba8290bd6967a1ab39cbb630be:/include/stg/subscriptions.h diff --git a/include/stg/subscriptions.h b/include/stg/subscriptions.h index 853cebe1..9ee9c64a 100644 --- a/include/stg/subscriptions.h +++ b/include/stg/subscriptions.h @@ -10,24 +10,23 @@ namespace STG class Connection { public: - Connection() noexcept : m_connected(false) {} + Connection() = default; Connection(const Connection&) = delete; Connection& operator=(const Connection&) = delete; Connection(Connection&&) = default; Connection& operator=(Connection&&) = default; - Connection(const std::function& f) noexcept : m_disconnect(f), m_connected(true) {} + Connection(const std::function& f) noexcept : m_disconnect(f) {} void disconnect() noexcept { - if (!m_connected) + if (!m_disconnect) return; m_disconnect(); - m_connected = false; + m_disconnect = {}; } private: std::function m_disconnect; - bool m_connected; }; class ScopedConnection @@ -53,7 +52,7 @@ template class Subscriptions { public: - using Callback = std::function; + using Callback = std::function; using Callbacks = std::list; Connection makeConn(typename Callbacks::iterator i) noexcept @@ -71,7 +70,7 @@ class Subscriptions template Connection add(C& c, void (C::*m)(T2s...)) { - return add([&c, m](Ts&&... values){ (c.*m)(std::forward(values)...); }); + return add([&c, m](const Ts&... values){ (c.*m)(values...); }); } void remove(typename Callbacks::iterator i) @@ -80,7 +79,7 @@ class Subscriptions m_callbacks.erase(i); } - void notify(Ts&&... values) + void notify(const Ts&... values) { std::lock_guard lock(m_mutex); for (auto& cb : m_callbacks)