operator==,<=>(std::counted_iterator)
迭代器概念 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迭代器原语 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
算法概念与工具 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
间接可调用概念 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
常用算法要求 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
工具 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迭代器适配器 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
流迭代器 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迭代器定制点 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迭代器操作 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
范围访问 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
成员函数 | ||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)(C++20)
|
||||
(C++20)
|
||||
非成员函数 | ||||
operator==operator<=>
(C++20)(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
辅助类 | ||||
(C++20)
|
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 | - | 迭代器适配器 |
返回值
注解
由于长度向下计数,而非向上, 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)
|
计算两个迭代器适配器间的距离 (函数模板) |