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<void ()>& f) noexcept : m_disconnect(f), m_connected(true) {}
+ Connection(const std::function<void ()>& 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<void ()> m_disconnect;
- bool m_connected;
};
class ScopedConnection
class Subscriptions
{
public:
- using Callback = std::function<void (Ts...)>;
+ using Callback = std::function<void (const Ts&...)>;
using Callbacks = std::list<Callback>;
Connection makeConn(typename Callbacks::iterator i) noexcept
template <typename C, typename... T2s>
Connection add(C& c, void (C::*m)(T2s...))
{
- return add([&c, m](Ts&&... values){ (c.*m)(std::forward<Ts>(values)...); });
+ return add([&c, m](const Ts&... values){ (c.*m)(values...); });
}
void remove(typename Callbacks::iterator i)
m_callbacks.erase(i);
}
- void notify(Ts&&... values)
+ void notify(const Ts&... values)
{
std::lock_guard lock(m_mutex);
for (auto& cb : m_callbacks)