#include <unordered_set>
#include <iostream>
struct Point {
int X, Y;
Point() : X(0), Y(0) {};
Point(const int x, const int y) : X(x), Y(y) {};
};
int main() {
auto hash = [](const Point& p) { return std::hash<int>()(p.X) * 31 + std::hash<int>()(p.Y); };
auto equal = [](const Point& p1, const Point& p2) { return p1.X == p2.X && p1.Y == p2.Y; };
std::unordered_set<Point, decltype(hash), decltype(equal)> mySet(8, hash, equal);
Point a, b(1, 2), c(b), d(3, 4);
mySet.emplace(a);
mySet.emplace(b);
mySet.emplace(c); // Insertion fails; element already exists.
c = d;
mySet.emplace(c);
mySet.emplace(1, 1);
for (auto const& pt : mySet) {
std::cout << "(" << pt.X << ", " << pt.Y << ")" << std::endl;
}
return 0;
}
I2luY2x1ZGUgPHVub3JkZXJlZF9zZXQ+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnN0cnVjdCBQb2ludCB7CiAgICBpbnQgWCwgWTsKCiAgICBQb2ludCgpIDogWCgwKSwgWSgwKSB7fTsKICAgIFBvaW50KGNvbnN0IGludCB4LCBjb25zdCBpbnQgeSkgOiBYKHgpLCBZKHkpIHt9Owp9OwoKaW50IG1haW4oKSB7CiAgICBhdXRvIGhhc2ggPSBbXShjb25zdCBQb2ludCYgcCkgeyByZXR1cm4gc3RkOjpoYXNoPGludD4oKShwLlgpICogMzEgKyBzdGQ6Omhhc2g8aW50PigpKHAuWSk7IH07CiAgICBhdXRvIGVxdWFsID0gW10oY29uc3QgUG9pbnQmIHAxLCBjb25zdCBQb2ludCYgcDIpIHsgcmV0dXJuIHAxLlggPT0gcDIuWCAmJiBwMS5ZID09IHAyLlk7IH07CiAgICBzdGQ6OnVub3JkZXJlZF9zZXQ8UG9pbnQsIGRlY2x0eXBlKGhhc2gpLCBkZWNsdHlwZShlcXVhbCk+IG15U2V0KDgsIGhhc2gsIGVxdWFsKTsKCiAgICBQb2ludCBhLCBiKDEsIDIpLCBjKGIpLCBkKDMsIDQpOwoKICAgIG15U2V0LmVtcGxhY2UoYSk7CiAgIC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