I want to store event_handler
into std::vector, then call listeners[index].handler_(args...)
.
I realise the above isn't possible, but I wonder if there are any alternatives I should consider.
template<class... Args>
using Handler = std::function<void(Args &&... args)>;
template<typename T>
struct event_handler {
event_handler(Handler<T> handler, bool once) : handler_(std::move(handler)), once_(once) {}
Handler<T> handler_;
bool once_;
};
std::vector<event_handler> listeners; // I known this line is wrong, here is example
Aucun commentaire:
Enregistrer un commentaire