operator==,!=,<,<=,>,>=,<=>(std::vector)_C++中文网
| 定义于头文件 |
||
| (1) | ||
| template< class T, class Alloc > bool operator==( const std::vector<T,Alloc>& lhs, |
(C++20 前) | |
| template< class T, class Alloc > constexpr bool operator==( const std::vector<T,Alloc>& lhs, |
(C++20 起) | |
| template< class T, class Alloc > bool operator!=( const std::vector<T,Alloc>& lhs, |
(2) | (C++20 前) |
| template< class T, class Alloc > bool operator<( const std::vector<T,Alloc>& lhs, |
(3) | (C++20 前) |
| template< class T, class Alloc > bool operator<=( const std::vector<T,Alloc>& lhs, |
(4) | (C++20 前) |
| template< class T, class Alloc > bool operator>( const std::vector<T,Alloc>& lhs, |
(5) | (C++20 前) |
| template< class T, class Alloc > bool operator>=( const std::vector<T,Alloc>& lhs, |
(6) | (C++20 前) |
| template< class T, class Alloc > constexpr /* see below */ operator<=>( const std::vector<T,Alloc>& lhs, |
(7) | (C++20 起) |
比较二个 vector 的内容。
1-2) 检查 lhs 与 rhs 的内容是否相等,即它们是否拥有相同数量的元素且 lhs 中每个元素与 rhs 的同位置元素比较相等。
7) 按字典序比较 lhs 与 rhs 的内容。如同通过在二个 vector 上以进行合成三路比较(见后述)的函数对象调用 std::lexicographical_compare_three_way 进行比较。返回类型同合成三路比较的结果类型。
给定分别作为左操作数与右操作数的两个 const E 左值 lhs 与 rhs (其中 E 为 T ),合成三路比较定义如下:
- 若 std::three_way_comparable_with<E, E> 得到满足则等价于 lhs <=> rhs ;
- 否则,若以 operator< 比较二个 const E 左值为良构且结果类型满足
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 被满足但未被实现,或使用 operator< 但 E 与 < 不建立全序,则 operator<=> 的行为未定义。
参数
返回值
1) 若 vector 内容相等则为 true ,否则为 false
2) 若 vector 内容不相等则为 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 ;
若 lhs 与 rhs 中的首对不等价元素无序则为 std::partial_ordering::unordered ;
否则为 std::strong::equal 。
复杂度
1-2) 若 lhs 与 rhs 的大小不同则为常数,否则与 vector 大小成线性
3-7) 与 vector 大小成线性