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` 為某個整數。
[編輯] 示例
#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(); }