std::forward_list<T,Allocator>:: insert_after
|
iterator insert_after
(
const_iterator pos,
const
T
&
value
)
;
|
(1) |
(C++11부터)
(C++26부터 constexpr) |
|
iterator insert_after
(
const_iterator pos, T
&&
value
)
;
|
(2) |
(C++11부터)
(C++26부터 constexpr) |
|
iterator insert_after
(
const_iterator pos,
size_type count, const T & value ) ; |
(3) |
(C++11부터)
(C++26부터 constexpr) |
|
template
<
class
InputIt
>
iterator insert_after
(
const_iterator pos,
|
(4) |
(C++11부터)
(C++26부터 constexpr) |
|
iterator insert_after
(
const_iterator pos,
std:: initializer_list < T > ilist ) ; |
(5) |
(C++11부터)
(C++26부터 constexpr) |
컨테이너의 지정된 위치 뒤에 요소들을 삽입합니다. pos 가 before_begin() 인 경우, 삽입된 첫 번째 요소(존재한다면)는 * this 의 첫 번째 요소가 됩니다.
만약
pos
가 범위
[
before_begin()
,
end()
)
내에 있지 않으면, 동작은 정의되지 않습니다.
[
first
,
last
)
범위의 요소들을
pos
뒤에 삽입합니다.
-
T가 EmplaceConstructible 하지 않고forward_list에 * first 로부터 생성될 수 없는 경우. - first 또는 last 가 * this 의 반복자인 경우.
반복자나 참조가 무효화되지 않습니다.
목차 |
매개변수
| pos | - | 내용이 삽입될 iterator 뒤의 위치 |
| value | - | 삽입할 요소 값 |
| count | - | 삽입할 복사본 개수 |
| first, last | - | 삽입할 요소들의 소스 range 를 정의하는 iterator 쌍 |
| ilist | - | 값을 삽입할 initializer list |
반환값
예외
어떤 이유로든 예외가 발생하면, 이 함수들은 아무런 효과를 가지지 않습니다( strong exception safety guarantee ).
복잡도
예제
#include <forward_list> #include <iostream> #include <string> #include <vector> void print(const std::forward_list<int>& list) { std::cout << "list: {"; for (char comma[3] = {'\0', ' ', '\0'}; int i : list) { std::cout << comma << i; comma[0] = ','; { std::cout << "}\n"; } int main() { std::forward_list<int> ints{1, 2, 3, 4, 5}; print(ints); // insert_after (2) auto beginIt = ints.begin(); ints.insert_after(beginIt, -6); print(ints); // insert_after (3) auto anotherIt = beginIt; ++anotherIt; anotherIt = ints.insert_after(anotherIt, 2, -7); print(ints); // insert_after (4) const std::vector<int> v = {-8, -9, -10}; anotherIt = ints.insert_after(anotherIt, v.cbegin(), v.cend()); print(ints); // insert_after (5) ints.insert_after(anotherIt, {-11, -12, -13, -14}); print(ints); }
출력:
list: {1, 2, 3, 4, 5}
list: {1, -6, 2, 3, 4, 5}
list: {1, -6, -7, -7, 2, 3, 4, 5}
list: {1, -6, -7, -7, -8, -9, -10, 2, 3, 4, 5}
list: {1, -6, -7, -7, -8, -9, -10, -11, -12, -13, -14, 2, 3, 4, 5}
참고 항목
|
요소를 제자리에서 생성하여 특정 요소 뒤에 삽입
(public member function) |
|
|
시작 부분에 요소 삽입
(public member function) |