命名空间
变体
操作

operator-(ranges::zip_view::sentinel)

来自 cppreference.cn
< cpp‎ | ranges‎ | zip view‎ | sentinel
 
 
范围库
范围适配器
 
 
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) 范围内的 iDIST(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();
}