#ifndef SOPHIAR2_TINY_SIGNAL_HPP #define SOPHIAR2_TINY_SIGNAL_HPP #include #include template class tiny_signal { public: using hook_type = boost::intrusive::list_base_hook< boost::intrusive::link_mode< boost::intrusive::auto_unlink>>; struct listener_type : public hook_type { virtual void on_signal_received(Args... args) = 0; }; using list_type = boost::intrusive::list< listener_type, boost::intrusive::constant_time_size>; void add_listener(listener_type &node) { if (node.is_linked()) { node.unlink(); } node_list.push_back(node); } void emit_signal(Args... args) { for (auto &node: node_list) { node.on_signal_received(args...); } } private: list_type node_list; }; #endif //SOPHIAR2_TINY_SIGNAL_HPP