operator-(ranges::zip_view::sentinel)
来自cppreference.com
| |
(1) | (C++23 起) |
| |
(2) | (C++23 起) |
计算 x 的底层迭代器元组和 y 的底层哨位元组之间的最小距离。
这些函数对常规的无限定或有限定查找不可见,而只能在 zip_view::sentinel<Const> 为实参的关联类时由实参依赖查找找到。
参数
| x | - | iterator |
| y | - | sentinel |
返回值
令 current_ 代表 x 的底层迭代器元组,并令 end_ 代表 y 的底层哨位元组。
令 DIST(x, y, i) 为对于某个整数 i 通过等价于 std::get<i>(x.current_) - std::get<i>(y.end_) 的表达式计算所得的距离。
1) 范围
0 ≤ i < sizeof...(Views) 中的所有 i 中的 DIST(x, y, i) 的最小绝对值2)
-(x - y)示例
运行此代码
#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();
}