fork download
  1. #include <vector>
  2. #include <set>
  3.  
  4. #include <algorithm>
  5. #include <functional>
  6.  
  7. struct point // A simple custom point structure
  8. {
  9. int x, y;
  10. };
  11.  
  12. // Functor created by the wizard
  13. // --------------------------------------------------
  14.  
  15. struct point_functor
  16. : public std::binary_function<point, point, bool>
  17. {
  18. bool operator() (const point &left, const point &right) const
  19. {
  20. if (left.x == right.x)
  21. return (left.y < right.y);
  22. else
  23. return (left.x < right.x);
  24. }
  25. };
  26.  
  27. // --------------------------------------------------
  28.  
  29. int main()
  30. {
  31. std::vector<point> v;
  32. std::sort(v.begin(), v.end(), point_functor()); //Compiles happily with point structures
  33.  
  34. std::set<point, point_functor> s;
  35. s.find(point()); //Compiles happily with point structures
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 2892KB
stdin
Standard input is empty
stdout
Standard output is empty