multiset::emplace
배치 힌트를 사용하여 위치에 생성된 구성 요소를 삽입합니다. (어떠한 복사 또는 이동 작업도 수행되지 않습니다)
template<class... Args>
iterator emplace(
Args&&... args);
매개 변수
Parameter |
설명 |
args |
멀티셋에 삽입할 요소를 생성하기 위해 전달된 인수입니다. |
반환 값
새로 삽입된 된 요소에 대한 반복기입니다.
설명
컨테이너 요소에 대한 어떠한 참조도 이 함수에 의해 무효화 되지 않지만 컨테이너의 모든 반복기를 무효화 할 수 있습니다.
Emplacement하는 동안, 예외가 나타나면, 컨테이너의 상태는 수정되지 않습니다.
예제
// multiset_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: ";
for (const auto& p : s) {
cout << "(" << p << ") ";
}
cout << endl;
}
int main()
{
multiset<string> s1;
s1.emplace("Anna");
s1.emplace("Bob");
s1.emplace("Carmine");
cout << "multiset modified, now contains ";
print(s1);
cout << endl;
s1.emplace("Bob");
cout << "multiset modified, now contains ";
print(s1);
cout << endl;
}
Output
multiset modified, now contains 3 elements: (Anna) (Bob) (Carmine)
multiset modified, now contains 4 elements: (Anna) (Bob) (Bob) (Carmine)
요구 사항
헤더: <설정>
네임스페이스: std