operator- (std::counted_iterator)
| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Non-member functions | ||||
|
(C++20)
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
operator-
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
| Helper classes | ||||
|
template
<
std::
common_with
<
I
>
I2
>
friend
constexpr
std::
iter_difference_t
<
I2
>
operator
-
(
|
(C++20以降) | |
2つのイテレータアダプタ間の距離を計算します。
x と y が同じシーケンスの要素を指していない場合、動作は未定義です。つまり、ある n が存在して、 std:: next ( x. base ( ) , x. count ( ) + n ) と std:: next ( y. base ( ) , y. count ( ) + n ) が同じ要素を参照する必要があります。
この関数テンプレートは通常の unqualified lookup または qualified lookup では可視化されず、 argument-dependent lookup によってのみ、std::counted_iterator<I>が引数の関連クラスである場合に見つけることができます。
目次 |
パラメータ
| x, y | - | 差を計算するイテレータアダプタ |
戻り値
y. count ( ) - x. count ( )
注記
length が増加ではなく減少するため、基となる式における operator - の引数の順序は逆転します。すなわち、 y が lhs となり、 x が rhs となります。
例
#include <initializer_list> #include <iterator> int main() { static constexpr auto v = {1, 2, 3, 4, 5, 6}; constexpr std::counted_iterator<std::initializer_list<int>::iterator> it1{v.begin(), 5}, it2{it1 + 3}, it3{v.begin(), 2}; static_assert(it1 - it2 == -3); static_assert(it2 - it1 == +3); // static_assert(it1 - it3 == -3); // UB: operator-のオペランドが同じシーケンスの // 要素を参照していない }
関連項目
|
counted_iteratorを進めるまたは戻す
(公開メンバ関数) |
|
|
(C++20)
|
イテレータを進める
(関数テンプレート) |
|
終端までの符号付き距離を計算する
(関数テンプレート) |