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
를 할당함
(public member function) |