operator- (ranges::zip_view:: sentinel )
|
||||||||||||||||||||||
| Range primitives | |||||||
|
|||||||
| Range concepts | |||||||||||||||||||
|
|||||||||||||||||||
| Range factories | |||||||||
|
|||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||
| Helper items | |||||||||||||||||
|
|
||||||||||||||||
| Member functions | ||||
| Deduction guides | ||||
| Iterator | ||||
| Member functions | ||||
| Non-member functions | ||||
| Sentinel | ||||
| Member functions | ||||
| Non-member functions | ||||
|
operator-
(zip_view::
iterator
,zip_view::
sentinel
)
|
|
template
<
bool
OtherConst
>
requires
(
std::
sized_sentinel_for
<
|
(1) | (自 C++23 起) |
|
template
<
bool
OtherConst
>
requires
(
std::
sized_sentinel_for
<
|
(2) | (自 C++23 起) |
计算 x 底层迭代器元组与 y 底层哨兵元组之间的最小距离。
这些函数对普通的
非限定查找
或
限定查找
不可见,仅当
zip_view::
sentinel
<Const>
作为参数的关联类时,才能通过
实参依赖查找
找到。
参数
| x | - | 一个 迭代器 |
| y | - | 一个 哨兵 |
返回值
令
current_
表示
x
的基础迭代器元组,
end_
表示
y
的基础哨位元组。
设
DIST
(x, y, i)
为由等价于
std
::
get
<
i
>
(
x.
current_
)
-
std
::
get
<
i
>
(
y.
end_
)
的表达式计算得出的距离,其中
i
为某个整数。
0 ≤ i < sizeof...(Views)
内所有
i
对应的
DIST
(x, y, i)
中绝对值最小的值
示例
#include <cassert> #include <deque> #include <list> #include <ranges> #include <vector> int main() { auto x = std::vector{1, 2, 3, 4}; auto y = std::deque{'a', 'b', 'c'}; auto z = {1.1, 2.2}; auto w = std::list{1, 2, 3}; auto p = std::views::zip(x, y, z); assert(p.begin() - p.end() == +2); assert(p.end() - p.begin() == -2); [[maybe_unused]] auto q = std::views::zip(x, y, w); // 以下代码会触发编译时错误,因为 std::list::iterator // 不支持计算距离所需的 operator-: // auto e = q.begin() - q.end(); }