hash_map::emplace
![]() |
---|
這個 API 已經過時。替代方案是 unordered_map 類別。 |
插入建構的項目就地入 hash_map。
template<class ValTy>
pair <iterator, bool> emplace(
ValTy&& _Val
);
參數
參數 |
說明 |
_Val |
包含用來提供資料移動建構項目將插入至 hash_map 類別 ,除非 hash_map 已經包含項目 (或,一般而言,索引鍵相等的已排序的項目)。 |
傳回值
emplace 成員函式來傳回 bool 元件傳回 true 的配對,如果插入已建立和,如果 hash_map 已經包含了索引鍵 Common Language Runtime 在定序,因此, Iterator 元件傳回位址或插入新項目的項目已經在位置項目。
若要存取由這個成員函式回傳的一對 pr Iterator 元件,請使用 pr.first ,解除參考它,請使用 *(pr.first)。 若要存取由這個成員函式回傳的一對 pr 之 bool 元件,請使用 pr.second,若要解除參考它,請使用 *(pr.second)。
備註
項目的 hash_map::value_type 是一組,因此元素,的值會與第一個元件等於這個機碼值和第二個元件的已排序配對等於這個項目之資料值。
從 Visual C++ .NET 2003 年開始, <hash_map> 和 <hash_set> 標頭檔的成員不在 std 命名空間中,,而是移至 stdext 命名空間。 如需詳細資訊,請參閱 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