10template <
typename Func>
21 int add(
const std::function<Func>& callback) {
22 callbacks.push_back(callback);
23 return callbacks.size() - 1;
30 void remove(
int callback_id) { callbacks[callback_id] =
nullptr; }
37 operator bool()
const {
38 return !callbacks.empty() && std::any_of(callbacks.begin(), callbacks.end(), [](
const std::function<Func>& f) { return f; });
45 template <
class... Args>
46 void call(Args&&... args)
const {
47 if (callbacks.empty()) {
51 for (
const auto& callback : callbacks) {
62 template <
class... Args>
68 std::vector<std::function<Func>> callbacks;
Callback slot to hold and trigger multiple callbacks.
Definition callback_slot.hpp:11
void call(Args &&... args) const
Call all the registered callbacks.
Definition callback_slot.hpp:46
void operator()(Args &&... args) const
Call all the registered callbacks.
Definition callback_slot.hpp:63
int add(const std::function< Func > &callback)
Add a new callback.
Definition callback_slot.hpp:21
void remove(int callback_id)
Remove a callback.
Definition callback_slot.hpp:30