map::emplace_hint
배치 힌트를 사용하여 위치에 생성된 구성 요소를 삽입합니다. (어떠한 복사 또는 이동 작업도 수행되지 않습니다)
template<class... Args>
iterator emplace_hint(
const_iterator where,
Args&&... args);
매개 변수
Parameter |
설명 |
args |
맵이 해당 요소를 이미 포함 하거나 또는 이것이 동일하게 정렬된 키를 가지는 요소를 이미 포함한 경우를 제외하고, 인수들은 삽입할 요소를 생성하여 맵에 입력하게 위해 전달됩니다. |
where |
정확한 지점에 삽입하기 위한 검색을 시작할 위치 (해당 지점이 where 바로 앞에 있는 경우, 삽입은 로그 시간 대신 분할된 일정한 시간에 발생할 수 있습니다.) |
반환 값
새로 삽입된 된 요소에 대한 반복기입니다.
요소가 이미 존재하여 삽입이 실패한 경우, 기존 요소 해당 키와 함께 반복기를 반환 합니다.
설명
이 함수에 의해 참조가 없거나 반복기가 무효화 됩니다.
Emplacement하는 동안, 예외가 나타나면, 컨테이너의 상태는 수정되지 않습니다.
요소의 값을 키 값과 같은 첫 번째 구성 요소와 요소의 데이터 값과 같은 두 번째 구성 요소를 사용하여 정렬된 된 쌍이 될 수 있도록 요소의 value_type 는 한 쌍으로 되어있습니다.
예제
// map_emplace.cpp
// compile with: /EHsc
#include <map>
#include <string>
#include <iostream>
using namespace std;
template <typename M> void print(const M& m) {
cout << m.size() << " elements: " << endl;
for (const auto& p : m) {
cout << "(" << p.first << "," << p.second << ") ";
}
cout << endl;
}
int main()
{
map<string, string> m1;
// Emplace some test data
m1.emplace("Anna", "Accounting");
m1.emplace("Bob", "Accounting");
m1.emplace("Carmine", "Engineering");
cout << "map starting data: ";
print(m1);
cout << endl;
// Emplace with hint
// m1.end() should be the "next" element after this emplacement
m1.emplace_hint(m1.end(), "Doug", "Engineering");
cout << "map modified, now contains ";
print(m1);
cout << endl;
}
Output
map starting data: 3 elements:
(Anna,Accounting) (Bob,Accounting) (Carmine,Engineering)
map modified, now contains 4 elements:
(Anna,Accounting) (Bob,Accounting) (Carmine,Engineering) (Doug,Engineering)
요구 사항
헤더: <맵>
네임스페이스: std