Go to the documentation of this file.
10 #include <unordered_map>
15 template<
typename ...Types>
21 std::unordered_map<int, std::function<void (Types...)>>
_functions = {};
27 template<
typename Func>
30 int id = this->_nextID++;
31 if constexpr(std::is_same_v<Func, std::function<
void (Types...)>>)
32 this->_functions[id] = std::move(callback);
34 this->_functions[id] = std::function<void (Types...)>(callback);
42 this->_functions.erase(
id);
47 for (
const auto &[_, callback] : this->_functions)
61 template<
typename Func>
std::unordered_map< int, std::function< void(Types...)> > _functions
The list of functions to call.
Definition: Callback.hpp:21
void operator()(Types ...args) const
Definition: Callback.hpp:45
int addCallback(Func callback)
Add a method to be called when this callback is invoked.
Definition: Callback.hpp:28
A callback where you can subscribe to and emit it.
Definition: Callback.hpp:16
Callback(Func callback)
Implicitly transform a callable into a callback.
Definition: Callback.hpp:62
~Callback()=default
A default destructor.
int _nextID
Definition: Callback.hpp:19
void removeCallback(int id)
Remove a function from this callback.
Definition: Callback.hpp:40
Callback()=default
A default constructor.
Callback & operator=(const Callback &)=default
A default assignment operator.