hash_map::emplace
![]() |
---|
這個 API 已經過時。這個選項是 unordered_map Class。 |
插入建構的項目就地入 hash_map。
template<class ValTy>
pair <iterator, bool> emplace(
ValTy&& _Val
);
參數
參數 |
描述 |
_Val |
用於提供設計階段移動建構要插入中的項目 hash_maphash_map Class ,除非已經包含該項目 (或,一般而言,索引鍵相等的已排序的項目)。 |
傳回值
emplace 成員函式傳回 bool 元件傳回 true 的配對,如果插入是進行錯誤的,如果 hash_map 已經包含索引鍵具有等值的順序,因此, Iterator 元件傳回位址或插入新項目的項目已經放置項目。
若要存取一組 pr 的 Iterator 元件 (此成員函式,請使用 pr.first傳回和解除參考它,請使用 *(pr.first)。 若要存取一組 pr 的 bool 元件 (此成員函式,請使用 pr.second傳回和解除參考它,請使用 *(pr.second)。
備註
項目的 hash_map::value_type 是一組,因此元素,的值會與第一個元件相等於這個機碼值和第二個元件的已排序配對相等於這個項目之資料值。
從 Visual C++ .NET 開始 Pocket PC, <hash_map> 和 <hash_set> 標頭檔 (Header File) 的成員不在 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