C++ 三路比较 (Three-way Comparison)
简介C++20 引入了三路比较运算符 <=>,也被称为”宇宙飞船运算符”(spaceship operator)。这个运算符可以一次性确定两个对象之间的所有比较关系(小于、等于、大于),大大简化了比较运算符的实现。 传统比较运算符的问题在 C++20 之前,如果我们想为一个自定义类型实现完整的比较运算符,需要分别实现六个运算符: class Point { public: int x, y; bool operator==(const Point& other) const { return x == other.x && y == other.y; } bool operator!=(const Point& other) const { return !(*this == other); } bool operator<(const Point& other) ...

