Namespaces
Variants

std::compare_partial_order_fallback

来自 zh.cppreference.net
 
 
 
定义于头文件 <compare>
inline namespace /* unspecified */ {
    inline constexpr /* unspecified */
        compare_partial_order_fallback = /* unspecified */;
}
(C++20 起)
调用签名
template< class T, class U >
    requires /* see below */
constexpr std::partial_ordering
    compare_partial_order_fallback( T&& t, U&& u ) noexcept(/* see below */);
(C++20 起)

对子表达式(subexpressions) 和 t 执行三路比较,u并产生类型为 std::partial_ordering 的结果,即使运算符 <=> 不可用。

如果 std::decay_t<T> 和 std::decay_t<U>> 类型相同,则 std::compare_partial_order_fallback(t, u) 是表达式等价(expression-equivalent)于:

  • std::partial_order(t, u),如果它是一个良构的表达式;
  • 否则,如果表达式 t == u ? std::partial_ordering::equivalent :
    t < u ? std::partial_ordering::less :
    u < t ? std::partial_ordering::greater :
             std::partial_ordering::unordered
    、t == u 和 t < u u < t均良构,且 decltype(t == u)、decltype(t < u) 和 decltype(u < t) 各自均满足 可布尔测试(boolean-testable)(除了 t 和 u 只求值一次),则为

。std::compare_partial_order_fallback(t, u)在所有其他情况下, 为病构,当其出现在模板实例化的直接上下文中时可能导致替换失败(substitution failure)。

定制点对象

名称 std::compare_partial_order_fallback 表示一个 定制点对象 ,这是一个字面量 semiregular 类类型的常量 函数对象 。有关详细信息,请参阅 定制点对象 。

示例

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 适用版本 发布时行为 正确行为
LWG 2114
( P2167R3 )
C++20 回退机制仅要求
返回类型可转换为 bool
约束条件已加强
LWG 3465 C++20 回退机制未要求 u < t 格式正确 现要求格式正确
LWG 4157 C++20 P2167R3 覆盖了 LWG 3465 的解决方案 已恢复原解决方案

参见

执行三路比较并生成 std::partial_ordering 类型的结果
(定制点对象)