operator==,<=>(std::inplace_vector)
ja.cppreference.net より
constexpr friend bool operator==( const std::inplace_vector<T, N>& lhs,
const std::inplace_vector<T, N>& rhs );
|
(1) | (C++26以降) |
constexpr friend synth-three-way-result<T>
operator<=>( const std::inplace_vector<T, N>& lhs,
const std::inplace_vector<T, N>& rhs );
|
(2) | (C++26以降) |
2つの std::inplace_vector の内容を比較します。
1)
lhs と rhs の内容が等しいかどうか調べます。つまり、同じ数の要素を持ち、 lhs の各要素が rhs の同じ位置の要素と等しいかどうか比較します。2)
lhs と rhs の内容を辞書順で比較します。比較は std::lexicographical_compare_three_way(lhs.begin(), lhs.end(),
rhs.begin(), rhs.end(), /*synth-three-way*/);
以下の条件のうち少なくとも1つを満たさなければなりません:
Tが three_way_comparable のモデルである。<が (おそらくconst修飾された)T型の値に対して定義され、<は全順序関係である。
演算子 <、 <=、 >、 >=、 != はそれぞれ と から operator<=>合成operator== されます。
パラメータ
| lhs, rhs | - | std::inplace_vector の比較対象となる内容 |
-
T
はオーバーロード(1)を使用するために
EqualityComparable
の要件を満たさなければならない
|
||
戻り値
1)
true
が
std::inplace_vector
の内容が等しい場合、
false
がそれ以外の場合。
2)
等価でない最初の要素ペアの相対的な順序(そのような要素が存在する場合)、
lhs
と
rhs
において、
lhs.
size
(
)
<=>
rhs.
size
(
)
それ以外の場合。
計算量
1)
サイズが異なる場合は定数時間、それ以外の場合は
std::inplace_vector
のサイズに対して線形時間。
2)
std::inplace_vector
のサイズに対して線形。
注記
関係演算子は synth-three-way によって定義され、可能な場合は operator <=> を、そうでない場合は operator < を使用します。
特に、要素自体が operator <=> を提供していないが、三方比較可能な型への暗黙変換が可能な場合、その変換が operator < の代わりに使用されます。
例
このコードを実行
#include <inplace_vector>
int main()
{
constexpr std::inplace_vector<int, 4>
a{1, 2, 3},
b{1, 2, 3},
c{7, 8, 9, 10};
static_assert
(""
"Compare equal containers:" &&
(a != b) == false &&
(a == b) == true &&
(a < b) == false &&
(a <= b) == true &&
(a > b) == false &&
(a >= b) == true &&
(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) < 0 &&
(a <=> c) != 0 &&
(a <=> c) <= 0 &&
"");
}