fork download
  1. #include <algorithm>
  2. #include <vector>
  3.  
  4.  
  5. struct Student {
  6. int get_average() const {
  7. return 42;
  8. }
  9. };
  10.  
  11. struct CompAverage
  12. {
  13. bool operator () (const Student & a, const Student & b) const
  14. {
  15. return a.get_average() < b.get_average();
  16. }
  17. };
  18.  
  19. using Student_IT = std::vector<Student>::const_iterator;
  20.  
  21. Student dispatch(const std::vector<Student> &all_students, Student_IT (*f)(Student_IT, Student_IT, CompAverage))
  22. {
  23. return *f(std::begin(all_students), std::end(all_students), CompAverage{});
  24. }
  25.  
  26. int main()
  27. {
  28. std::vector<Student> v(42);
  29.  
  30. dispatch(v, &std::min_element);
  31. dispatch(v, &std::max_element);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty