名前空間
変種
操作

operator-(ranges::zip_view::sentinel)

From cppreference.com
< cpp‎ | ranges‎ | zip view‎ | sentinel
 
 
Rangesライブラリ
Rangeアダプタ
 
 
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 - an イテレータ
y - a セ sentinel

[編集] 戻り値

x の基底となるイテレータのタプルを current_y の基底となるセ sentinel のタプルを end_ とします。

整数 i に対して、std::get<i>(x.current_) - std::get<i>(y.end_) と同等の式で計算される距離を DIST(x, y, 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();
}
English 日本語 中文(简体) 中文(繁體)