Skip to content

Instantly share code, notes, and snippets.

@emiflake
Created February 2, 2017 17:47
Show Gist options
  • Save emiflake/f7d6764a22a90330f253e289164e6c5c to your computer and use it in GitHub Desktop.
Save emiflake/f7d6764a22a90330f253e289164e6c5c to your computer and use it in GitHub Desktop.
:(
template <class T>
class EventHandler
{
vector<void(*)(Event<T>&)> subs;
public:
EventHandler::EventHandler();
void EventHandler::subscribe(void(*handler)(Event<T>&));
void EventHandler::emit(Event<T> value);
};
template<class T>
inline EventHandler<T>::EventHandler()
{
this->subs = vector<void(*)(Event<T>&)>();
}
template<class T>
inline void EventHandler<T>::subscribe(void(*handler)(Event<T>&))
{
this->subs.push_back(handler);
}
template<class T>
inline void EventHandler<T>::emit(Event<T> value)
{
for (void(*sub)(Event<T>&) : this->subs) {
sub(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment