operator==,<=> (std::counted_iterator)
| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Non-member functions | ||||
|
operator==
operator<=>
(C++20)
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
| Helper classes | ||||
|
template
<
std::
common_with
<
I
>
I2
>
friend
constexpr
bool
operator
==
(
|
(1) | (C++20 起) |
|
template
<
std::
common_with
<
I
>
I2
>
friend
constexpr
strong_ordering operator
<=>
(
|
(2) | (C++20 起) |
比较底层长度(即到末尾的距离)。
<=>
比较底层长度。
如果 x 和 y 不指向同一序列的元素,则行为未定义。也就是说,必须存在某个 n ,使得 std:: next ( x. base ( ) , x. count ( ) + n ) 和 std:: next ( y. base ( ) , y. count ( ) + n ) 指向同一元素。
<
、
<=
、
>
、
>=
和
!=
运算符分别由
operator
<=>
和
operator
==
自动合成。
此函数模板对普通的 非限定查找 或 限定查找 不可见,仅当 std::counted_iterator<I> 作为实参的关联类时,才能通过 实参依赖查找 找到。
目录 |
参数
| x, y | - | 迭代器适配器 |
返回值
注释
由于 length 是递减计数而非递增,底层比较表达式中 operator <=> 的参数顺序是相反的,即 y 是 lhs , x 是 rhs 。
示例
#include <initializer_list> #include <iterator> int main() { static constexpr auto v = {1, 2, 3, 4, 5, 6}; constexpr std::counted_iterator<std::initializer_list<int>::iterator> it1{v.begin(), 5}, it2{v.begin(), 5}, it3{v.begin() + 1, 4}, it4{v.begin(), 0}; static_assert(it1 == it2); static_assert(it2 != it3); static_assert(it2 < it3); static_assert(it1 <= it2); static_assert(it3 != std::default_sentinel); static_assert(it4 == std::default_sentinel); // it2 == std::counted_iterator{v.begin(), 4}; // UB: 操作数未引用同一序列的元素 }
参见
检查到末尾的距离是否等于
0
(函数模板) |
|
|
(C++20)
|
前进迭代器
(函数模板) |
|
(C++20)
|
计算两个迭代器适配器间的距离
(函数模板) |