1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| template <typename T> struct less_than_comparable { friend bool operator>(const T& a, const T& b) { return !(a <= b); } friend bool operator>=(const T& a, const T& b) { return !(a < b); } friend bool operator<=(const T& a, const T& b) { return (a < b) || (a == b); } };
class point : less_than_comparable<point> { private: int x; int y; public: point(int _x, int _y) :x(_x), y(_y){} friend bool operator<(const point& p1, const point& p2) { return p1.distance() < p2.distance(); } friend bool operator==(const point& p1, const point& p2) { return p1.distance() == p2.distance(); } double distance() const { return sqrt(x * x + y * y); } };
|