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