fork download
  1. #include <iostream>
  2. #include <set>
  3.  
  4. struct Foo
  5. {
  6. int _x, _y, _z;
  7. Foo(int x, int y, int z): _x(x), _y(y), _z(z) {}
  8. bool operator<(const Foo& rhs) const
  9. {
  10. return (_x < rhs._x) && (_x + _y < rhs._x + rhs._y) &&
  11. (_x + _y + _z < rhs._x + rhs._y + rhs._z) ; // majorization
  12. }
  13. };
  14.  
  15. int main()
  16. {
  17. std::set<Foo> setFoo;
  18. // try to insert 2 equivalent elements
  19. setFoo.insert(Foo{1, 2, 3});
  20. if(setFoo.insert(Foo{1, 2, 0}).second == false) // failed to insert
  21. std::cout << "Equivalent element already in the set!" << std::endl;
  22. }
  23.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Equivalent element already in the set!