hash_map::emplace

说明说明

此 API 已过时。另一种方法是 unordered_map Class

插入构造的元素就地到 hash_map 中。

template<class ValTy>
    pair <iterator, bool> emplace(
        ValTy&& _Val
);

参数

Parameter

描述

_Val

用于的值将构造要插入的元素。hash_map Class,除非 hash_map 已包含该元素 (或,通常,键相同地排序) 的元素。

返回值

emplace 成员函数返回 bool 元素返回 true 的对,如果插入是使和错误的,如果 hash_map 已经包含一个键具有等效值顺序,并且,迭代器元素返回地址插入或新元素的元素已找到其中的元素。

访问对的迭代器元素 pr 由该成员函数,使用 pr.first返回和取消引用它,使用 *(pr.first)。访问对的 bool 元素 pr 由该成员函数,使用 pr.second返回和取消引用它,使用 *(pr.second)。

备注

元素的 hash_map::value_type 是对,因此,元素的值将排序的匹配的第一个元素等于键值和第二个元素为等于元素的数据值。

从 Visual C++ .NET 2003 中启动,<hash_map><hash_set> 标头文件的成员中不再标准,命名空间,而是将 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

请参见

参考

hash_map Class

标准模板库