fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <list>
  4.  
  5. class Foo
  6. {
  7. int _m;
  8. public:
  9. Foo(int m): _m(m){}
  10. friend bool operator==(const Foo& lhs, const Foo& rhs);
  11. };
  12.  
  13. bool operator==(const Foo& lhs, const Foo& rhs)
  14. {
  15. return lhs._m == rhs._m;
  16. }
  17.  
  18. int main()
  19. {
  20. Foo foo1{42};
  21. Foo foo2{24};
  22.  
  23. std::list<Foo> lst;
  24. lst.push_back(foo1);
  25. lst.push_back(foo2);
  26. auto it = std::find(lst.begin(), lst.end(), foo1);
  27. if(it != lst.end())
  28. std::cout << "Found!" << std::endl;
  29. else
  30. std::cout << "Not found!" << std::endl;
  31. }
  32.  
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
Found!