fork download
  1. #include <iostream>
  2. struct A {
  3. int x;
  4. std::string name;
  5. A(int v, std::string n):x(v), name(n) {};
  6. void do_it() const { std::cout << name.c_str() << "\n"; }
  7. };
  8. bool operator<( A lhs, A rhs ) { return lhs.x < rhs.x; }
  9.  
  10. #include <algorithm>
  11. int main() {
  12. A a(5, "A");
  13. A b(5, "B");
  14. std::min( a, b ).do_it();
  15. std::min( b, a ).do_it();
  16. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
A
B