std::partial_order
來自 cppreference.com
定義於標頭檔案 <compare> |
||
inline namespace /* unspecified */ { inline constexpr /* unspecified */ partial_order = /* unspecified */; |
(C++20 起) | |
呼叫簽名 (Call signature) |
||
template< class T, class U > requires /* 見下文 */ |
||
使用三向比較比較兩個值,並生成型別為 std::partial_ordering
的結果。
令 t 和 u 為表示式,而 T
和 U
分別表示 decltype((t)) 和 decltype((u)),則 std::partial_order(t, u) 表示式等價於
- 若 std::is_same_v<std::decay_t<T>, std::decay_t<U>> 為 true
- std::partial_ordering(partial_order(t, u)),如果它是在不包含
std::partial_order
宣告的上下文中進行過載決議後形成良構表示式, - 否則,std::partial_ordering(std::compare_three_way()(t, u)),如果它良構,
- 否則,std::partial_ordering(std::weak_order(t, u)),如果它良構。
- std::partial_ordering(partial_order(t, u)),如果它是在不包含
- 在所有其他情況下,該表示式格式錯誤,當它出現在模板例項化的直接上下文中時,可能導致 替換失敗。
自定義點物件
名稱 std::partial_order
表示一個*自定義點物件*,它是一個常量 函式物件,屬於 字面量 semiregular
類型別。為了說明目的,其型別中 cv 非限定版本表示為 __partial_order_fn
。
所有 __partial_order_fn
的例項都相等。在相同引數上呼叫不同 __partial_order_fn
型別例項的效果是等價的,無論表示例項的表示式是左值還是右值,以及是否 const 限定(然而,volatile 限定的例項不要求可呼叫)。因此,std::partial_order
可以自由複製,並且其副本可以互換使用。
給定一組型別 Args...
,如果 std::declval<Args>()... 滿足上述 std::partial_order
引數的要求,則 __partial_order_fn
遵循以下模型:
- std::invocable<__partial_order_fn, Args...>,
- std::invocable<const __partial_order_fn, Args...>,
- std::invocable<__partial_order_fn&, Args...>,以及
- std::invocable<const __partial_order_fn&, Args...>.
否則,__partial_order_fn
的函式呼叫運算子不參與過載決議。
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 另請參閱
(C++20) |
支援所有6個運算子,不可替換,並允許不可比較值的三路比較的結果型別 (類) |
(C++20) |
執行三向比較並生成型別為 std::strong_ordering 的結果(自定義點物件) |
(C++20) |
執行三向比較並生成型別為 std::weak_ordering 的結果(自定義點物件) |
執行三向比較並生成型別為 std::partial_ordering 的結果,即使 operator<=> 不可用(自定義點物件) |