名前空間
変種
操作

operator==, <=> (std::inplace_vector)

From cppreference.com
 
 
 
 
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) lhsrhs の要素が等しいかどうかをチェックします。つまり、要素数が同じで、lhs の各要素が rhs の同じ位置の要素と等しく比較できるかどうかをチェックします。
2) lhsrhs の要素を辞書順で比較します。比較は以下のように呼び出すことで行われます。
std::lexicographical_compare_three_way(lhs.begin(), lhs.end(),
                                       rhs.begin(), rhs.end(), synth-three-way);
.
戻り値の型はsynth-three-wayの戻り値の型(つまり、synth-three-way-result <T>)です。
次のいずれかの条件が満たされている必要があります。
  • Tthree_way_comparableのモデルです。
  • 型(おそらくconst修飾された)Tの値に対して<が定義されており、<は全順序関係です。
   それ以外の場合、動作は未定義です。

<, <=, >, >=, != 演算子は、それぞれ operator<=>operator== から合成されます。

目次

[編集] パラメータ

lhs, rhs - 比較するstd::inplace_vector
-
オーバーロード (1) を使用するには、TEqualityComparable の要件を満たす必要があります。

[編集] 戻り値

1) std::inplace_vector の要素が等しい場合は true、それ以外の場合は false
2) lhsrhs の最初の非等価な要素ペアの相対順序。そのような要素が存在する場合、それ以外の場合は lhs.size() <=> rhs.size()

[編集] 複雑さ

1) lhsrhs のサイズが異なる場合は定数時間。それ以外の場合は std::inplace_vector のサイズに線形時間。
2) std::inplace_vector のサイズに線形時間。

[編集] 注意

関係演算子はsynth-three-wayを介して定義されます。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 &&
    "");
}
English 日本語 中文(简体) 中文(繁體)