operator-(ranges::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); // The following code fires a compile-time error because std::list::iterator // does not support operator- that is needed to calculate the distance: // auto e = q.begin() - q.end(); }