fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct T{
  7. string name;
  8. T(string n):name(n){};
  9. };
  10.  
  11. bool operator < (const T& l, const T *r) {
  12. cout << "LEFT:" << l.name << " ... " << r->name << endl;
  13. return l.name < r->name;
  14. }
  15. bool operator < (const T *l, const T &r) {
  16. cout << "RIGHT:" << l->name << " ... " << r.name << endl;
  17. return l->name < r.name;
  18. }
  19.  
  20. int main() {
  21. vector<T*> t;
  22. t.push_back(new T("one"));
  23. t.push_back(new T("three"));
  24. t.push_back(new T("two"));
  25.  
  26. bool has_3 = binary_search( t.begin(), t.end(), T("two") ) ;
  27. if( has_3 ){
  28. cout <<"Its there" << endl;
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
RIGHT:three ... two
RIGHT:two ... two
LEFT:two ... two
Its there