std::counted_iterator<I>:: counted_iterator
From cppreference.net
<
cpp
|
iterator
|
counted iterator
C++
Iterator library
| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::counted_iterator
| Member functions | ||||
|
counted_iterator::counted_iterator
|
||||
| Non-member functions | ||||
|
(C++20)
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
| Helper classes | ||||
|
constexpr
counted_iterator
(
)
requires
std::
default_initializable
<
I
>
=
default
;
|
(1) | (C++20以降) |
|
constexpr
counted_iterator
(
I x,
std::
iter_difference_t
<
I
>
n
)
;
|
(2) | (C++20以降) |
|
template
<
class
I2
>
requires
std::
convertible_to
<
const
I2
&
, I
>
|
(3) | (C++20以降) |
新しいイテレータアダプタを構築します。
1)
デフォルトコンストラクタ。
値初期化
により基盤となるイテレータを初期化し、基盤となる
length
を
0
で初期化します。結果のイテレータに対する操作は、値初期化された
I
に対する対応する操作が定義された動作を持つ場合にのみ、定義された動作を持ちます。
2)
基盤となるイテレータは
std
::
move
(
x
)
で初期化され、基盤となる
length
は
n
で初期化されます。
n
が負の場合の動作は未定義です。
3)
基となるイテレータと
length
は、
other
のそれらで初期化されます。
パラメータ
| x | - | アダプトするイテレータ |
| n | - | 終端までの距離 |
| other | - | 変換するイテレータアダプタ |
例
このコードを実行
#include <algorithm> #include <initializer_list> #include <iostream> #include <iterator> int main() { static constexpr auto pi = {3, 1, 4, 1, 5, 9, 2}; // (1) デフォルトコンストラクタ: constexpr std::counted_iterator<std::initializer_list<int>::iterator> i1{}; static_assert(i1 == std::default_sentinel); static_assert(i1.count() == 0); // (2) イテレータと長さをそれぞれ初期化: constexpr std::counted_iterator<std::initializer_list<int>::iterator> i2{ pi.begin(), pi.size() - 2 }; static_assert(i2.count() == 5); static_assert(*i2 == 3 && i2[1] == 1); // (3) 変換コンストラクタ: std::counted_iterator<std::initializer_list<const int>::iterator> i3{i2}; std::ranges::copy(i3, std::default_sentinel, std::ostream_iterator<const int>{std::cout, " "}); }
出力:
3 1 4 1 5
関連項目
別の
counted_iterator
を代入する
(公開メンバ関数) |