简体   繁体   English

C++ 宇宙飞船算子多级比较?

[英]C++ spaceship operator multilevel compare?

Does the new C++20 spaceship operator allow a concise way of expressing short-circuited multiple-criteria comparison?新的 C++20 宇宙飞船运算符是否允许以简洁的方式表达短路的多标准比较? 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:通常的tie -and-compare 方法也适用于 spaceship:

return std::tie(lhs.x, lhs.y) <=> std::tie(rhs.x, rhs.y);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM