std::insert_iterator
| 헤더 <iterator>
|
||
template< class Container >
class insert_iterator : public std::iterator<std::output_iterator_tag,
void, void, void, void>
|
(C++17까지) | |
template< class Container >
class insert_iterator;
|
(C++17부터) | |
std::insert_iterator는 LegacyOutputIterator로서, 생성 시 제공된 반복자가 가리키는 위치에 컨테이너에 요소를 삽입합니다. 반복자(역참조 여부와 관계없이)에 값이 할당될 때마다 컨테이너의 insert() 멤버 함수가 호출됩니다. std::insert_iterator의 증가는 아무 작업도 수행하지 않습니다.
멤버 타입
| 멤버 타입 | 정의 | ||||
iterator_category
|
std:: output_iterator_tag | ||||
value_type
|
void | ||||
difference_type
|
|
||||
pointer
|
void | ||||
reference
|
void | ||||
container_type
|
Container
|
|
멤버 타입
|
(C++17까지) |
멤버 함수
새로운
insert_iterator
를 생성합니다
(public member function) |
|
|
객체를 연관된 컨테이너에 삽입합니다
(public member function) |
|
|
no-op
(public member function) |
|
|
no-op
(public member function) |
멤버 객체
| 멤버 이름 | 정의 |
container
(보호된 멤버 객체)
|
Container*
타입의 포인터
|
iter
(보호된 멤버 객체)
|
Container::iterator
(C++20 이전)
ranges::iterator_t<Container>
(C++20 이후)
타입의 반복자
|
예제
#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
#include <vector>
int main()
{
std::vector<int> v{1, 2, 3, 4, 5};
std::list<int> l{-1, -2, -3};
std::copy(v.begin(), v.end(), // may be simplified with std::inserter
std::insert_iterator<std::list<int>>(l, std::next(l.begin())));
for (int n : l)
std::cout << n << ' ';
std::cout << '\n';
}
출력:
-1 1 2 3 4 5 -2 -3
참고 항목
|
인수로부터 추론된 타입의
std::insert_iterator
를 생성함
(함수 템플릿) |
|
|
컨테이너의 끝에 삽입하기 위한 반복자 어댑터
(클래스 템플릿) |
|
|
컨테이너의 앞에 삽입하기 위한 반복자 어댑터
(클래스 템플릿) |