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



描述

C++ 函式std::unordered_multimap::operator=() 將一個無序多對映的內容移動到另一個,並在必要時修改大小。

宣告

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

C++11

unordered_multimap& operator=(unordered_multimap&& umm);

引數

umm − 另一個相同型別的無序多對映物件。

返回值

返回this指標。

時間複雜度

線性,即 O(n)

示例

以下示例演示了 std::unordered_multimap::operator=() 函式的用法。

#include <iostream>
#include <unordered_map>

using namespace std;

int main(void) {
   unordered_multimap<char, int> umm1 = {
            {'a', 1},
            {'b', 2},
            {'c', 3},
            {'d', 4},
            {'e', 5},
            };

   unordered_multimap<char, int> umm2;

   umm2 = move(umm1);

   cout << "Unordered multimap contains following elements" << endl;

   for (auto it = umm2.begin(); it != umm2.end(); ++it)
      cout << it->first << " = " << it->second << endl;

   return 0;
}

讓我們編譯並執行上面的程式,這將產生以下結果:

Unordered multimap contains following elements
e = 5
a = 1
b = 2
c = 3
d = 4
unordered_map.htm
廣告