Does the new C++20 spaceship operator allow a concise way of expressing short-circuited multiple-criteria comparison? Something better than this:
const firstCriteriaComparisonResult = lhs.x <=> rhs.x;
return firstCriteriaComparisonResult != 0 ? firstCriteriaComparisonResult : lhs.y <=> rhs.y;
The usual tie
-and-compare approach works with spaceship too:
return std::tie(lhs.x, lhs.y) <=> std::tie(rhs.x, rhs.y);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With