Skip to content

Instantly share code, notes, and snippets.

@jmlyn
Created June 5, 2020 21:20
Show Gist options
  • Select an option

  • Save jmlyn/51f8582fcce978ca775e73b0e1da8561 to your computer and use it in GitHub Desktop.

Select an option

Save jmlyn/51f8582fcce978ca775e73b0e1da8561 to your computer and use it in GitHub Desktop.
// Example program
#include <iostream>
#include <string>
#include <vector>
#include <functional>
class Event {
public:
void Subscribe(std::function<void(void)> fn) {
mSubscribers.emplace_back(fn);
}
void Raise() {
for (auto subscriber : mSubscribers) {
subscriber();
}
}
private:
std::vector<std::function<void(void)>> mSubscribers;
};
int main()
{
Event onNavigationDone;
onNavigationDone.Subscribe([]() {
std::cout << "Function called!" << std::endl;
});
onNavigationDone.Raise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment