hash_map::emplace
참고
이 API는 사용되지 않습니다.unordered_map 클래스를 대신 사용하는 것이 좋습니다.
Inserts an element constructed in place into a hash_map.
template<class ValTy>
pair <iterator, bool> emplace(
ValTy&& _Val
);
매개 변수
Parameter |
설명 |
_Val |
The value used to move construct an element to be inserted into the hash_map 클래스 unless the hash_map already contains that element (or, more generally, an element whose key is equivalently ordered). |
반환 값
The emplace member function returns a pair whose bool component returns true if an insertion was made and false if the hash_map already contained an element whose key had an equivalent value in the ordering, and whose iterator component returns the address where a new element was inserted or where the element was already located.
이 멤버 함수로 인해 반환된 pr 쌍의 반복기 구성 요소에 액세스 하려면 pr.first 를 사용하고, 역참조하려면 *(pr.first) 를 사용합니다. To access the bool component of a pair pr returned by this member function, use pr.second, and to dereference it, use *(pr.second).
설명
The hash_map::value_type of an element is a pair, so that the value of an element will be an ordered pair with the first component equal to the key value and the second component equal to the data value of the element.
Beginning with Visual C++ .NET 2003, members of the <hash_map> and <hash_set> header files are no longer in the std namespace, but rather have been moved into the stdext namespace. 자세한 내용은 stdext 네임스페이스를 참조하십시오.
예제
// hash_map_emplace.cpp
// compile with: /EHsc
#include<hash_map>
#include<iostream>
#include <string>
int main()
{
using namespace std;
using namespace stdext;
hash_map<int, string> hm1;
typedef pair<int, string> is1(1, "a");
hm1.emplace(move(is1));
cout << "After the emplace insertion, hm1 contains:" << endl
<< " " << hm1.begin()->first
<< " => " << hm1.begin()->second
<< endl;
}
요구 사항
헤더: <hash_map>
네임스페이스: stdext