Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MoveTest.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <set>
- #include <functional>
- using namespace std;
- template <typename ...Args>
- using delegate = std::function<void(Args...)>;
- template <typename ...Args>
- class Event
- {
- private:
- using func = delegate<Args...>;
- std::set<func> eventSet;
- public:
- void operator+=(func f)
- {
- eventSet.insert(f);
- }
- void operator-=(func f)
- {
- eventSet.erase(f);
- }
- void operator()(Args...a)
- {
- for (auto x : eventSet)
- x(a...);
- }
- };
- void PrintNum(int x) {
- std::cout << x << std::endl;
- }
- int main() {
- int a = 45;
- Event<int> event;
- event += ([&](int x) { PrintNum(x); });
- event(3);
- system("pause");
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement