首页 > 解决方案 > 为什么 std::strong_ordering 有一个“等效”值?

问题描述

的有效值为std::strong_orderinglessequal和。然而,看起来和是相等的(,可互换的),因为在这两种情况下,仅展示字段都等于零,并且没有其他状态可供仅展示构造函数初始化。equivalentgreaterstrong_ordering::equivalentstrong_ordering::equalvalue

strong_ordering没有任何单独 的值是有道理的equivalent,因为当排序很强时,等价的值总是相等的。但是,为 做strong_ordering::equivalent一个同义词strong_ordering::equal而不是根本不定义它有什么意义呢?

标签: c++c++20spaceship-operator

解决方案


This allows C::equivalent to be defined for all comparison categories C. There used to be five of them, all of which had this, now just the three.

If you need something like that, it helps to have it. And it costs nothing to provide, so... there it is.


推荐阅读