名稱空間
變體
操作

std::weak_order

來自 cppreference.com
< cpp‎ | 工具
 
 
 
定義於標頭檔案 <compare>
inline namespace /* unspecified */ {

    inline constexpr /* unspecified */ weak_order = /* unspecified */;

}
(C++20 起)
呼叫簽名 (Call signature)
template< class T, class U >

    requires /* 見下文 */

constexpr std::weak_ordering weak_order(T&& t, U&& u) noexcept(/* see below */);

使用三路比較對兩個值進行比較,併產生型別為 std::weak_ordering 的結果。

tu 為表示式,TU 分別表示 decltype((t))decltype((u))std::weak_order(t, u) 等價於

目錄

自定義點物件

名稱 std::weak_order 指示一個*定製點物件*,它是一個 字面量 semiregular 類型別的 const 函式物件。為便於闡述,其型別的 cv-unqualified 版本表示為 __weak_order_fn

__weak_order_fn 的所有例項都相等。在相同引數上呼叫不同型別的 __weak_order_fn 例項的效果是等價的,無論表示例項的表示式是左值還是右值,以及是否為 const 限定(但是,volatile 限定的例項不需要可呼叫)。因此,std::weak_order 可以自由複製,並且其副本可以互換使用。

給定一組型別 Args...,若 std::declval<Args>()... 滿足上述 std::weak_order 引數的要求,則 __weak_order_fn 滿足

否則,__weak_order_fn 的任何函式呼叫運算子都不參與過載決議。

[編輯] IEEE 浮點型別的嚴格弱序

xy 是相同 IEEE 浮點型別的值,weak_order_less(x, y) 是一個布林結果,指示 x 是否在 C++ 標準定義的嚴格弱序中先於 y

  • xy 都不是 NaN,則 weak_order_less(x, y) == true 當且僅當 x < y,即所有表示相同浮點值的表示都等價;
  • x 是負 NaN 且 y 不是負 NaN,則 weak_order_less(x, y) == true
  • x 不是正 NaN 且 y 是正 NaN,則 weak_order_less(x, y) == true
  • xy 都是同符號的 NaN,則 (weak_order_less(x, y) || weak_order_less(y, x)) == false,即所有同符號的 NaN 都等價。

[編輯] 示例

[編輯] 參閱

支援所有6個運算子但不可替換的三路比較的結果型別
(類) [編輯]
執行三向比較並生成型別為 std::strong_ordering 的結果
(定製點物件)[編輯]
執行三路比較併產生 std::partial_ordering 型別的結果
(定製點物件)[編輯]
執行三路比較併產生 std::weak_ordering 型別的結果,即使 operator<=> 不可用
(定製點物件)[編輯]