名前空間
変種
操作

operator==,!=,<,<=,>,>=,<=>(std::forward_list)

提供: cppreference.com
 
 
 
 
ヘッダ <forward_list> で定義
template< class T, class Alloc >

bool operator==( const std::forward_list<T,Alloc>& lhs,

                 const std::forward_list<T,Alloc>& rhs );
(1)
template< class T, class Alloc >

bool operator!=( const std::forward_list<T,Alloc>& lhs,

                 const std::forward_list<T,Alloc>& rhs );
(2) (C++20未満)
template< class T, class Alloc >

bool operator<( const std::forward_list<T,Alloc>& lhs,

                const std::forward_list<T,Alloc>& rhs );
(3) (C++20未満)
template< class T, class Alloc >

bool operator<=( const std::forward_list<T,Alloc>& lhs,

                 const std::forward_list<T,Alloc>& rhs );
(4) (C++20未満)
template< class T, class Alloc >

bool operator>( const std::forward_list<T,Alloc>& lhs,

                const std::forward_list<T,Alloc>& rhs );
(5) (C++20未満)
template< class T, class Alloc >

bool operator>=( const std::forward_list<T,Alloc>& lhs,

                 const std::forward_list<T,Alloc>& rhs );
(6) (C++20未満)
template< class T, class Alloc >

/* see below */ operator<=>( const std::forward_list<T,Alloc>& lhs,

                             const std::forward_list<T,Alloc>& rhs );
(7) (C++20以上)

2つの forward_list の内容を比較します。

1-2) lhsrhs の内容が等しいかどうか調べます。 つまり、それらが同じ個数の要素を持ち、 lhs 内のそれぞれの要素が rhs 内の同じ位置の要素と等しいかどうか比較します。
3-6) lhsrhs の内容を辞書的に比較します。 比較は std::lexicographical_compare と同等の関数によって行われます。
7) lhsrhs の内容を辞書的に比較します。 比較は合成された三項比較 (後述) を行う関数オブジェクトを用いて2つの forward_list に対して std::lexicographical_compare_three_way を呼んだかのように行われます。 戻り値の型は合成された三項比較の結果の型と同じです。 2つの const E 左辺値 lhs および rhs がそれぞれ左の被演算子および右の被演算子として与えられたとき (ただし ET です)、合成された三項比較は以下のように定義されます。
  • 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<=> はオーバーロード解決に参加しません。
three_way_comparable_with または boolean-testable が満たされないかモデル化されない場合、または < 演算子が使用されるけれども E< が全順序を確立しない場合、 operator<=> の動作は未定義です。

[編集] 引数

lhs, rhs - 内容を比較する forward_list
-
オーバロード (1-2) を使用するためには TEqualityComparable の要件を満たさなければなりません。
-
オーバロード (3-6) を使用するためには TLessThanComparable の要件を満たさなければなりません。 順序関係は全順序を確立しなければなりません。

[編集] 戻り値

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) lhs の内容が rhs の内容より辞書的に小さい場合は std::strong_ordering::less
lhs の内容が rhs の内容より辞書的に大きい場合は std::strong_ordering::greater
lhsrhs の同等でない最初の要素が順序付けできない場合は std::partial_ordering::unordered
そうでなけ���ば std::strong::equal

[編集] 計算量

forward_list のサイズに線形