C++ 無序多對映庫 - operator=() 函式



描述

C++ 函式 std::unordered_multimap::operator=() 將初始化列表中的元素複製到無序多對映中。

宣告

以下是來自 std::unordered_map() 標頭檔案的 std::unordered_multimap::operator=() 函式的宣告。

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
unordered_map.htm
廣告