operator-(std::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 | - | iterator |
| y | - | sentinel |
戻り値
current_
を
x
の基盤となるイテレータのタプルとし、
end_
を
y
の基盤となるセンチネルのタプルとする。
DIST
(x, y, i)
を、ある整数
i
に対して
std
::
get
<
i
>
(
x.
current_
)
-
std
::
get
<
i
>
(
y.
end_
)
と同等の式で計算される距離とする。
0 ≤ i < sizeof...(Views)
内の全ての
i
における
DIST
(x, y, 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); // 以下のコードはコンパイル時エラーを発生させます。std::list::iteratorは // 距離を計算するために必要なoperator-をサポートしていないためです: // auto e = q.begin() - q.end(); }