operator+ (std::counted_iterator)
|
friend
constexpr
counted_iterator operator
+
(
std::
iter_difference_t
<
I
>
n,
const
counted_iterator
&
x
)
|
(C++20以降) | |
n だけ進められたイテレータアダプタを返します。 n が x 内に記録された長さを超える場合(すなわち x + n が未定義動作を引き起こす場合)、動作は未定義です。
この関数は通常の unqualified lookup または qualified lookup では可視化されず、 argument-dependent lookup によってのみ、std::counted_iterator<I>が引数の関連クラスである場合に見つけることができます。
目次 |
パラメータ
| n | - | イテレータをインクリメントする位置の数 |
| x | - | インクリメントするイテレータアダプタ |
戻り値
x + n に等しいイテレータアダプタ。
例
#include <iostream> #include <iterator> #include <list> #include <vector> int main() { std::vector v{0, 1, 2, 3, 4, 5}; std::counted_iterator<std::vector<int>::iterator> p{v.begin() + 1, 4}; std::cout << "*p:" << *p << ", count:" << p.count() << '\n'; std::counted_iterator<std::vector<int>::iterator> q{2 + p}; std::cout << "*q:" << *q << ", count:" << q.count() << '\n'; std::list l{6, 7, 8, 9}; std::counted_iterator<std::list<int>::iterator> r{l.begin(), 3}; std::cout << "*r:" << *r << ", count:" << r.count() << '\n'; // auto s{2 + r}; // error: the underlying iterator does // not model std::random_access_iterator }
出力:
*p:1, count:4 *q:3, count:2 *r:6, count:3
関連項目
|
counted_iteratorを進めるまたは戻す
(公開メンバ関数) |
|
|
(C++20)
|
2つのイテレータアダプタ間の距離を計算する
(関数テンプレート) |
|
終端までの符号付き距離を計算する
(関数テンプレート) |