fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. template<typename... TArgs>
  8. class Delegate;
  9. template<typename... TArgs>
  10. class Delegate<void, TArgs...>
  11. {
  12. private:
  13. typedef std::function<void(TArgs...)> Func;
  14. std::vector<Func> funcs;
  15.  
  16. public:
  17. template<typename T> Delegate& operator+=(T mFunc) { funcs.push_back(Func(mFunc)); return *this; }
  18. void operator()(TArgs... mParams) { /*for (auto& f : funcs) f(mParams...);* gcc 4.5 does not support ranged based for*/ }
  19. };
  20.  
  21. void test(int x, int y) { x - y; }
  22. int main()
  23. {
  24. Delegate<void, int, int> d2;
  25. d2 += test;
  26. }
Success #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
Standard output is empty