C++ Unordered_map 库 - unordered_map() 函数
描述
C++ 函数 std::unordered_map::unordered_map() 构造一个 unordered_map 与 other 使用移动语义的内容。
声明
以下是 std::unordered_map::unordered_map() 函数形式 std::unordered_map 头的声明。
C++11
unordered_map(unordered_map&& um);
参数
um − 另一个相同类型的 unordered_map 对象。
返回值
构造函数从不返回值。
时间复杂度
常数,即 O(1)
示例
以下示例显示了 std::unordered_map::unordered_map() 函数的用法。
#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) {
unordered_map<char, int> um1 = {
{'a', 1},
{'b', 2},
{'c', 3},
{'d', 4},
{'e', 5}
};
unordered_map<char, int>um2(move(um1));
cout << "Unordered_map contains following elements" << endl;
for (auto it = um2.begin(); it != um2.end(); ++it)
cout << it->first << " = " << it->second << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Unordered_map contains following elements e = 5 a = 1 b = 2 c = 3 d = 4

