std::inplace_vector<T,N>::emplace
template< class... Args >
constexpr iterator emplace( const_iterator position, Args&&... args );
|
(C++26부터) | |
컨테이너에 새 요소를 pos 바로 앞에 삽입합니다. 일반적으로 요소는 컨테이너가 제공하는 위치에 제자리에서 요소를 구성하기 위해 배치 new를 사용하여 구성됩니다. 인수 args...는 std::forward<Args>(args)...로 생성자에 전달됩니다.
| 이 섹션은 불완전합니다 |
매개변수
| pos | - | 새 요소가 생성될 반복자 앞 위치 |
| args | - | 요소의 생성자로 전달될 인자들 |
| 타입 요구사항 | ||
-
T
는 다음 요구사항을 충족해야 함:
MoveAssignable
,
MoveInsertable
및
EmplaceConstructible
.
|
||
반환값
삽입된 요소에 대한 반복자.
복잡도
pos 와 end() 사이의 거리에 선형적으로 비례합니다.
예외
std::bad_alloc 을 던집니다 - 호출 이전에 size ( ) == capacity ( ) 인 경우. 이 함수는 효과가 없습니다 ( 강력한 예외 안전성 보장 ).
삽입된 요소의 초기화 또는
LegacyInputIterator
연산에 의해 발생하는 모든 예외.
[
0
,
pos
)
범위의 요소는 수정되지 않습니다.
예제
#include <cassert>
#include <inplace_vector>
#include <iostream>
#include <new>
#include <utility>
int main()
{
using P = std::pair<int, int>;
using I = std::inplace_vector<P, 3>;
auto nums = I{{0, 1}, {2, 3}};
auto it = nums.emplace(nums.begin() + 1, -1, -2);
assert((*it == P{-1, -2}));
assert((nums == I{P{0, 1}, {-1, -2}, {2, 3}}));
try
{
nums.emplace(nums.begin(), 1, 3); // throws: no space
}
catch(const std::bad_alloc& ex)
{
std::cout << ex.what() << '\n';
}
}
가능한 출력:
std::bad_alloc
참고 항목
|
요소 삽입
(public member function) |
|
|
끝에 제자리에서 요소 생성
(public member function) |