问题描述
新的 C++20 飞船运算符是否允许以简洁的方式来表达短路的多标准比较?比这更好的东西:
const firstCriteriaComparisonResult = lhs.x <=> rhs.x;
return firstCriteriaComparisonResult != 0 ? firstCriteriaComparisonResult : lhs.y <=> rhs.y;
解决方法
通常的 tie
-and-compare 方法也适用于宇宙飞船:
return std::tie(lhs.x,lhs.y) <=> std::tie(rhs.x,rhs.y);