operator==,!=,<,<=,>,>=,<=>(std::forward_list)
| ヘッダ <forward_list> で定義 |
||
| template< class T, class Alloc > bool operator==( const std::forward_list<T, Alloc>& lhs, |
(1) | (C++11以降) |
| template< class T, class Alloc > bool operator!=( const std::forward_list<T, Alloc>& lhs, |
(2) | (C++11以降) (C++20まで) |
| template< class T, class Alloc > bool operator<( const std::forward_list<T, Alloc>& lhs, |
(3) | (C++11以降) (C++20まで) |
| template< class T, class Alloc > bool operator<=( const std::forward_list<T, Alloc>& lhs, |
(4) | (C++11以降) (C++20まで) |
| template< class T, class Alloc > bool operator>( const std::forward_list<T, Alloc>& lhs, |
(5) | (C++11以降) (C++20まで) |
| template< class T, class Alloc > bool operator>=( const std::forward_list<T, Alloc>& lhs, |
(6) | (C++11以降) (C++20まで) |
| template< class T, class Alloc > synth-three-way-result<T> |
(7) | (C++20以降) |
2つのforward_listの要素を比較します。
rhs.begin(), rhs.end(), synth-three-way) を呼び出すかのように実行されます。-
Tはthree_way_comparableのモデルです。 - 型(おそらくconst修飾された)
Tの値に対して<が定義されており、<は全順序関係です。
|
|
(C++20以降) |
目次 |
[編集] パラメータ
| lhs, rhs | - | 比較するforward_list |
-オーバーロード(1,2)を使用するには、TはEqualityComparableの要件を満たす必要があります。 | ||
-オーバーロード(3-6)を使用するには、TはLessThanComparableの要件を満たす必要があります。順序関係は全順序を確立する必要があります。 | ||
[編集] 戻り値
forward_listの要素が等しい場合は true、それ以外の場合は false。forward_listの要素が等しくない場合は true、それ以外の場合は false。[編集] 計算量
forward_listのサイズに線形。
[編集] 備考
|
関係演算子は、要素型のoperator<を介して定義されます。 |
(C++20まで) |
|
関係演算子はsynth-three-wayを介して定義されます。synth-three-wayは、可能であればoperator<=>を使用し、そうでなければoperator<を使用します。 特に、要素自身がoperator<=>を提供しないが、三方比較可能な型に暗黙的に変換できる場合、その変換がoperator<の代わりに使用されます。 |
(C++20以降) |
[編集] 例
#include <cassert> #include <compare> #include <forward_list> int main() { const std::forward_list a{1, 2, 3}, b{1, 2, 3}, c{7, 8, 9, 10}; assert ("" "Compare equal containers:" && (a != b) == false && (a == b) == true && (a < b) == false && (a <= b) == true && (a > b) == false && (a >= b) == true && (a <=> b) != std::weak_ordering::less && (a <=> b) != std::weak_ordering::greater && (a <=> b) == std::weak_ordering::equivalent && (a <=> b) >= 0 && (a <=> b) <= 0 && (a <=> b) == 0 && "Compare non equal containers:" && (a != c) == true && (a == c) == false && (a < c) == true && (a <= c) == true && (a > c) == false && (a >= c) == false && (a <=> c) == std::weak_ordering::less && (a <=> c) != std::weak_ordering::equivalent && (a <=> c) != std::weak_ordering::greater && (a <=> c) < 0 && (a <=> c) != 0 && (a <=> c) <= 0 && ""); }
[編集] 欠陥報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 3431 | C++20 | operator<=>はTを必要としませんでしたthree_way_comparableのモデルとするために |
要求するようになった |