hash_map::emplace

备注

此 API 已过时。替代为 unordered_map 类

插入元素构造已到 hash_map。

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

参数

参数

说明

_Val

用于移动的值构造要插入的元素到 hash_map 类,除非 hash_map 已经包含该元素 (即,一般,键相同顺序排列) 的元素。

返回值

emplace 成员函数返回布尔组件返回 true 的对,则插入是使和 false,如果 hash_map 已包含了具有等效值,键顺序,以及迭代器组件返回地址的新元素插入或的元素已经位于的位置。

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

备注

hash_map::value_type 元素是一对,因此,元素的值将与组件等于第一个值和第二个关键组件的一种有序的 to-string 等于元素的数据值。

从 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

请参见

参考

hash_map 类

标准模板库