unordered_multimap::emplace()
描述 (Description)
C ++函数std::unordered_multimap::emplace()通过插入新元素来扩展容器。
此成员函数将容器大小增加一个。
声明 (Declaration)
以下是std :: unordered_multimap :: emplace()函数形式std :: unordered_map()头的声明。
C++11
template <class... Args>
iterator emplace(Args&&... args );
参数 (Parameters)
args - 转发给元素构造函数的参数。
返回值
返回新插入元素的迭代器。
例子 (Example)
以下示例显示了std :: unordered_multimap :: emplace()函数的用法。
#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) {
unordered_multimap<char, int> umm = {
{'a', 1},
{'b', 2},
{'c', 3},
{'d', 4},
{'e', 5}
};
umm.emplace('b', 2);
umm.emplace('c', 3);
cout << "Unordered multimap contains following elements" << endl;
for (auto it = umm.begin(); it != umm.end(); ++it)
cout << it->first << " = " << it->second << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Unordered multimap contains following elements
e = 5
a = 1
b = 2
b = 2
c = 3
c = 3
d = 4