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 | ||||
|
(C++20)
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
operator-
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
| Helper classes | ||||
|
template
<
std::
common_with
<
I
>
I2
>
friend
constexpr
std::
iter_difference_t
<
I2
>
operator
-
(
|
(C++20 起) | |
计算两个迭代器适配器之间的距离。
如果 x 和 y 不指向同一序列的元素,则行为未定义。也就是说,必须存在某个 n 使得 std:: next ( x. base ( ) , x. count ( ) + n ) 和 std:: next ( y. base ( ) , y. count ( ) + n ) 指向同一元素。
此函数模板对普通的 非限定查找 或 限定查找 不可见,仅当 std::counted_iterator<I> 作为参数关联类时,通过 实参依赖查找 才能找到该模板。
目录 |
参数
| x, y | - | 用于计算差值的迭代器适配器 |
返回值
y. count ( ) - x. count ( )
备注
由于 长度 是递减计数而非递增,底层表达式中 operator - 的参数顺序是相反的,即 y 是 左操作数 而 x 是 右操作数 。
示例
#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{it1 + 3}, it3{v.begin(), 2}; static_assert(it1 - it2 == -3); static_assert(it2 - it1 == +3); // static_assert(it1 - it3 == -3); // UB: operator- 的操作数未引用 // 同一序列的元素 }
参见
递增或递减
counted_iterator
(公开成员函数) |
|
|
(C++20)
|
推进迭代器
(函数模板) |
|
计算到末尾的带符号距离
(函数模板) |