Created
May 15, 2012 15:54
-
-
Save klmr/2702833 to your computer and use it in GitHub Desktop.
Multicast function demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "multicast.hpp" | |
void f(int n) { | |
std::cout << "f(" << n << ")\n"; | |
} | |
struct g { | |
void operator ()(int n) { | |
std::cout << "g::()(" << n << ")\n"; | |
} | |
}; | |
void h(double n) { | |
std::cout << "h(static_cast<double>(" << n << "))\n"; | |
} | |
int main() { | |
util::multifunction<void(int)> event; | |
auto f_tok = event += f; | |
auto g_tok = event += g(); | |
auto h_tok = event += h; | |
event(42); | |
std::cout << "\nRemoving g\n"; | |
event -= g_tok; | |
event(23); | |
std::cout << "\nRemoving h\n"; | |
event -= h_tok; | |
event(101); | |
std::cout << "\nRemoving f\n"; | |
event -= f_tok; | |
event(97); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment