fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <functional>
  4.  
  5. static void fn1(int x, int y)
  6. {
  7. std::cout << x << " " << y << std::endl;
  8. }
  9.  
  10. static void fn2(int x, int *y, double z)
  11. {
  12. std::cout << x << " " << *y << " " << z << std::endl;
  13. }
  14.  
  15. static void fn3(const char* x, bool y)
  16. {
  17. std::cout << x << " " << std::boolalpha << y << std::endl;
  18. }
  19.  
  20. int main()
  21. {
  22. std::vector<std::function<void()>> binds;
  23. int i = 20;
  24.  
  25. binds.push_back(std::bind(&fn1, 1, 2));
  26. binds.push_back(std::bind(&fn1, 3, 4));
  27. binds.push_back(std::bind(&fn2, 1, &i, 3.99999));
  28. binds.push_back(std::bind(&fn2, 3, &i, 0.8971233921));
  29. binds.push_back(std::bind(&fn3, "test1", true));
  30. binds.push_back(std::bind(&fn3, "test2", false));
  31.  
  32. for (auto fn : binds) fn();
  33. }
Success #stdin #stdout 0s 4488KB
stdin
Standard input is empty
stdout
1 2
3 4
1 20 3.99999
3 20 0.897123
test1 true
test2 false