operator==,!=,<,<=,>,>=,<=>(std::forward_list)
提供: cppreference.com
< cpp | container | forward list
ヘッダ <forward_list> で定義
|
||
template< class T, class Alloc > bool operator==( const std::forward_list<T,Alloc>& lhs, |
(1) | |
template< class T, class Alloc > bool operator!=( const std::forward_list<T,Alloc>& lhs, |
(2) | (C++20未満) |
template< class T, class Alloc > bool operator<( const std::forward_list<T,Alloc>& lhs, |
(3) | (C++20未満) |
template< class T, class Alloc > bool operator<=( const std::forward_list<T,Alloc>& lhs, |
(4) | (C++20未満) |
template< class T, class Alloc > bool operator>( const std::forward_list<T,Alloc>& lhs, |
(5) | (C++20未満) |
template< class T, class Alloc > bool operator>=( const std::forward_list<T,Alloc>& lhs, |
(6) | (C++20未満) |
template< class T, class Alloc > /* see below */ operator<=>( const std::forward_list<T,Alloc>& lhs, |
(7) | (C++20以上) |
2つの forward_list
の内容を比較します。
1-2)
lhs
と rhs
の内容が等しいかどうか調べます。 つまり、それらが同じ個数の要素を持ち、 lhs
内のそれぞれの要素が rhs
内の同じ位置の要素と等しいかどうか比較します。7)
lhs
と rhs
の内容を辞書的に比較します。 比較は合成された三項比較 (後述) を行う関数オブジェクトを用いて2つの forward_list
に対して std::lexicographical_compare_three_way を呼んだかのように行われます。 戻り値の型は合成された三項比較の結果の型と同じです。 2つの const E 左辺値 lhs
および rhs
がそれぞれ左の被演算子および右の被演算子として与えられたとき (ただし E
は T
です)、合成された三項比較は以下のように定義されます。
- std::three_way_comparable_with<E, E> が満たされる場合は、 lhs <=> rhs と同等です。
- そうでなく、2つの const E 左辺値の < 演算子による比較が well-formed であり結果の型が
boolean-testable
の場合は、以下と同等です。
lhs < rhs ? std::weak_ordering::less : rhs < lhs ? std::weak_ordering::greater : std::weak_ordering::equivalent
- そうでなければ、合成された三項比較は定義されず、 operator<=> はオーバーロード解決に参加しません。
boolean-testable
が満たされないかモデル化されない場合、または < 演算子が使用されるけれども E
と <
が全順序を確立しない場合、 operator<=> の動作は未定義です。[編集] 引数
lhs, rhs | - | 内容を比較する forward_list
|
-オーバロード (1-2) を使用するためには T は EqualityComparable の要件を満たさなければなりません。
| ||
-オーバロード (3-6) を使用するためには T は LessThanComparable の要件を満たさなければなりません。 順序関係は全順序を確立しなければなりません。
|
[編集] 戻り値
1)
forward_list
の内容が等しい場合は true、そうでなければ false。2)
forward_list
の内容が等しくない場合は true、そうでなければ false。3)
lhs
の内容が rhs
の内容より辞書的に小さい場合は true、そうでなければ false。4)
lhs
の内容が rhs
の内容より辞書的に小さいまたは等しい場合は true、そうでなければ false。5)
lhs
の内容が rhs
の内容より辞書的に大きい場合は true、そうでなければ false。6)
lhs
の内容が rhs
の内容より辞書的に大きいまたは等しい場合は true、そうでなければ false。7)
そうでなけ���ば std::strong::equal。
lhs
の内容が rhs
の内容より辞書的に小さい場合は std::strong_ordering::less、lhs
の内容が rhs
の内容より辞書的に大きい場合は std::strong_ordering::greater、lhs
と rhs
の同等でない最初の要素が順序付けできない場合は std::partial_ordering::unordered、そうでなけ���ば std::strong::equal。
[編集] 計算量
forward_list
のサイズに線形