#include <iostream>
#include <set>
struct Foo
{
int _x, _y, _z;
Foo(int x, int y, int z): _x(x), _y(y), _z(z) {}
bool operator<(const Foo& rhs) const
{
return (_x < rhs._x) && (_x + _y < rhs._x + rhs._y) &&
(_x + _y + _z < rhs._x + rhs._y + rhs._z) ; // majorization
}
};
int main()
{
std::set<Foo> setFoo;
// try to insert 2 equivalent elements
setFoo.insert(Foo{1, 2, 3});
if(setFoo.insert(Foo{1, 2, 0}).second == false) // failed to insert
std::cout << "Equivalent element already in the set!" << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c2V0PgoKc3RydWN0IEZvbwp7CiAgICBpbnQgX3gsIF95LCBfejsKICAgIEZvbyhpbnQgeCwgaW50IHksIGludCB6KTogX3goeCksIF95KHkpLCBfeih6KSB7fQogICAgYm9vbCBvcGVyYXRvcjwoY29uc3QgRm9vJiByaHMpIGNvbnN0CiAgICB7CiAgICAgICAgcmV0dXJuIChfeCA8IHJocy5feCkgJiYgKF94ICsgX3kgPCByaHMuX3ggKyByaHMuX3kpICYmCiAgICAgICAgICAgICAgIChfeCArIF95ICsgX3ogPCByaHMuX3ggKyByaHMuX3kgKyByaHMuX3opIDsgLy8gbWFqb3JpemF0aW9uCiAgICB9Cn07CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6c2V0PEZvbz4gc2V0Rm9vOwogICAgLy8gdHJ5IHRvIGluc2VydCAyIGVxdWl2YWxlbnQgZWxlbWVudHMKICAgIHNldEZvby5pbnNlcnQoRm9vezEsIDIsIDN9KTsgCiAgICBpZihzZXRGb28uaW5zZXJ0KEZvb3sxLCAyLCAwfSkuc2Vjb25kID09IGZhbHNlKSAvLyBmYWlsZWQgdG8gaW5zZXJ0CiAgICAgICAgc3RkOjpjb3V0IDw8ICJFcXVpdmFsZW50IGVsZW1lbnQgYWxyZWFkeSBpbiB0aGUgc2V0ISIgPDwgc3RkOjplbmRsOwp9Cg==