Namespaces
Variants

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

From 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 起)

比较两个 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 ) ;
实现。
返回类型为 synth-three-way 的返回类型(即 synth-three-way-result  < T > )。
必须满足以下至少一个条件:
  • T 满足 three_way_comparable 概念。
  • 为(可能 const 限定的) T 类型值定义了 < 运算符,且 < 构成全序关系。
否则行为未定义。

< <= > >= != 运算符分别由 operator <=> operator == 合成。

目录

参数

lhs, rhs - 待比较内容的 std::inplace_vector 对象
-
T 必须满足 EqualityComparable 要求才能使用重载 (1)

返回值

1) true 如果 std::inplace_vector 的内容相等,否则为 false
2) 若存在非等价元素对,则为 lhs rhs 中首对非等价元素的相对顺序;否则为 lhs. size ( ) <=> rhs. size ( )

复杂度

1) lhs rhs 大小不同时为常数时间复杂度,否则与 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
    (""
        "比较相等容器:" &&
        (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 &&
        "比较不相等容器:" &&
        (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 &&
    "");
}