C++ Unordered_multimap 库 - operator=() 函数
描述
C++ 函数 std::unordered_multimap::operator=() 将初始值设定项列表中的元素复制到 unordered_multimap。
声明
以下是 std::unordered_multimap::operator=() 函数形式 std::unordered_map() 头的声明。
C++11
unordered_multimap& operator=(intitializer_list<value_type> il);
参数
il − 初始化列表。
返回值
返回 this 指针。
时间复杂度
线性,即平均情况下的 O(n)。
二次,即在最坏情况下为 O(n2)。
示例
以下示例显示了 std::unordered_multimap::operator=() 函数的用法。
#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) {
unordered_multimap<char, int> umm;
umm = {
{'a', 1},
{'b', 2},
{'c', 3},
{'d', 4},
{'e', 5},
};
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 d = 4 c = 3 b = 2 a = 1

