ClientServerProject/event.h

25 lines
481 B
C
Raw Normal View History

2021-02-09 23:02:05 -05:00
#pragma once
#include <functional>
template<typename ...T>
class event
{
std::vector <std::function<bool(T...)>> callbacks;
public:
auto operator+=(std::function<bool(T...)> callback) -> event<T...>&
{
callbacks.emplace_back(callback);
return *this;
}
auto reset() -> void
{
callbacks.clear();
}
auto execute(T... data) -> void
{
for (auto& callback : callbacks)
if (callback(data...)) /* true = handled... */
break;
}
};