fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4. #include <limits>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. using MyFunc = std::function<int()>;
  10.  
  11. int f1() { return 1; }
  12. int f2() { return 15;}
  13. int f3() { return 3; }
  14.  
  15. int main() {
  16. std::vector<MyFunc> my_functions{f1, f2, f3};
  17. std::vector<int> my_results;
  18. my_results.reserve(my_functions.size());
  19.  
  20. for (auto const &f : my_functions) {
  21. my_results.push_back(f());
  22. }
  23. auto max_it = std::max_element(std::begin(my_results), std::end(my_results));
  24. cout << *max_it << endl;
  25.  
  26. int max = std::numeric_limits<int>::min();
  27.  
  28. for (auto &f : my_functions) {
  29. max = std::max(max, f());
  30. }
  31.  
  32. cout << max << endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
15
15