fork download
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <functional>
  5.  
  6.  
  7. int functor1()
  8. {
  9. return -1;
  10. }
  11.  
  12. int functor2(int a)
  13. {
  14. return a;
  15. }
  16.  
  17. int functor3(int a, int b)
  18. {
  19. return a + b;
  20. }
  21.  
  22. void doSomethingWithThisFunctor(const std::function<void()>& functor)
  23. {
  24. functor();
  25. }
  26.  
  27. int main()
  28. {
  29. doSomethingWithThisFunctor(std::bind(functor1));
  30. doSomethingWithThisFunctor(std::bind(functor2, 5));
  31.  
  32. auto lambda = [](int a, int b, int c) -> void {std::cout << "lambda expr = " << a + b << std::endl; };
  33.  
  34.  
  35. std::function<void()> myFunctor = std::bind(lambda, 1, 1, 2);
  36.  
  37. myFunctor();
  38.  
  39. //doSomethingWithThisFunctor(std::bind(lambda, 5, 5));
  40. }
  41.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
lambda expr = 2