Skip to content

Instantly share code, notes, and snippets.

@vbo
Created July 26, 2013 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbo/6090142 to your computer and use it in GitHub Desktop.
Save vbo/6090142 to your computer and use it in GitHub Desktop.
//
// Clang build cmdline:
// $ clang++ ./set.cpp -Wall -Werror -Wfatal-errors -std=c++11 -stdlib=libc++ -o set.out
//
#include <iostream>
#include <unordered_set>
struct Point {
int x, y;
Point(int x = 0, int y = 0) {
this->x = x;
this->y = y;
}
bool operator==(Point const& p) const {
return this->x == p.x && this->y == p.y;
}
};
namespace std {
template<> struct hash<Point> {
size_t operator()(const Point &pt) const {
return std::hash<int>()(pt.x) ^ std::hash<int>()(pt.y);
}
};
}
typedef std::unordered_set<Point> points_set_t;
int main() {
Point point1(1, 5);
Point point2(1, 1);
Point point3(1, 5);
points_set_t points;
points.insert(point1);
points.insert(point2);
points.insert(point3);
for (points_set_t::const_iterator it = points.begin(); it != points.end(); it++) {
std::cout << it->x << ":" << it->y << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment