fork download
  1. #include <functional>
  2. #include <iostream>
  3.  
  4. double function_a(double a, double b, double c, double d)
  5. {
  6. std::cout << "function_a(" << a << ", " << b << ", " << c << ", " << d << ")\n";
  7. return a;
  8. }
  9.  
  10. double function_b(double a, double b, int t, int u, double c)
  11. {
  12. std::cout << "function_b(" << a << ", " << b << ", " << t << ", " << u << ", " << c << ")\n";
  13. return a;
  14. }
  15.  
  16. struct second_func
  17. {
  18. second_func(int t, int u, double c) :t(t), u(u), c(c) {}
  19.  
  20. double operator()(double a, double b) { return function_b(a, b, t, u, c); }
  21.  
  22. int t;
  23. int u;
  24. double c;
  25. };
  26.  
  27.  
  28. void PerformAnalysis(std::function<double(double, double)> func)
  29. {
  30. func(4.0, 5.0);
  31. }
  32.  
  33. int main()
  34. {
  35. auto first_func = [](double a, double b) { return function_a(a, b, 60.0, 2.1); };
  36.  
  37. // or:
  38. // double c = 60.0;
  39. // double d = 1.2;
  40. // auto first_func = [=](double a, double b) { return function_a(a, b, c, d); };
  41.  
  42. PerformAnalysis(first_func);
  43. PerformAnalysis(second_func(5, 90, 2.6));
  44. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
function_a(4, 5, 60, 2.1)
function_b(4, 5, 5, 90, 2.6)