Namespaces
Variants

operator- (ranges::zip_view:: sentinel )

From cppreference.net
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 の基となるセンチネルタプル間の最小距離を計算します。

これらの関数は通常の unqualified lookup または qualified lookup では可視化されず、 argument-dependent lookup によってのみ発見され、その場合も 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();
}