fork(2) download
  1. #include <vector>
  2. #include <functional>
  3.  
  4. template<class T, class... Args> class FuncList {
  5. public:
  6. std::vector<std::function<T(Args...)>> mFuncs;
  7.  
  8. void operator()(Args... args) {
  9. for (auto fn : mFuncs)
  10. fn(args...);
  11. }
  12. };
  13.  
  14. void mul(int x, int y) {
  15. printf("%i\n", x * y);
  16. }
  17.  
  18. auto add = [] (int x, int y) {printf("%i\n", x + y);};
  19.  
  20. int main() {
  21. FuncList<void, int, int> testFncs;
  22. testFncs.mFuncs.push_back(add);
  23. testFncs.mFuncs.push_back(mul);
  24. testFncs(5, 6);
  25. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
11
30