名稱空間
變體
操作

operator-(ranges::zip_view::sentinel)

來自 cppreference.com
< cpp‎ | ranges‎ | zip view‎ | sentinel
 
 
範圍庫 (Ranges library)
範圍介面卡 (Range adaptors)
 
 
template< bool OtherConst >

    requires (std::sized_sentinel_for<
                ranges::sentinel_t</*maybe-const*/<Const, Views>>,
                ranges::iterator_t</*maybe-const*/<OtherConst, Views>>> && ...)
friend constexpr
    std::common_type_t<ranges::range_difference_t</*maybe-const*/<OtherConst, Views>>...>

operator-( const iterator<OtherConst>& x, const sentinel& y );
(1) (C++23 起)
template< bool OtherConst >

    requires (std::sized_sentinel_for<
                ranges::sentinel_t</*maybe-const*/<Const, Views>>,
                ranges::iterator_t</*maybe-const*/<OtherConst, Views>>> && ...)
friend constexpr
    std::common_type_t<ranges::range_difference_t</*maybe-const*/<OtherConst, Views>>...>

operator-( const sentinel& y, const iterator<OtherConst>& x );
(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` 為某個整數。

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);
 
    // 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();
}