C++ 對映庫 - multimap() 函式



描述

C++ 函式std::multimap::multimap() 使用移動語義構造一個包含其他內容的多對映。

宣告

以下是來自 std::map 標頭檔案的 std::multimap::multimap() 函式的宣告。

C++11

multimap (multimap&& other);
multimap (multimap&& other, const allocator_type& alloc);

引數

  • other - 另一個相同型別的多對映物件。

  • alloc - 分配器物件。

返回值

建構函式不返回值。

異常

如果丟擲異常,對容器沒有影響。

時間複雜度

線性,即 O(n)

示例

以下示例演示了 std::multimap::multimap() 函式的使用。

#include <iostream>
#include <map>

using namespace std;

int main(void) {
   /* Multimap with duplicates */
   multimap<char, int> m1 = {
         {'a', 1},
         {'a', 2},
         {'b', 3},
         {'c', 4},
         {'c', 5},
               };

   multimap<char, int>m2(move(m1));

   cout << "Multimap contains following elements:" << endl;

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

   return 0;
}

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

Multimap contains following elements:
a = 1
a = 2
b = 3
c = 4
c = 5
map.htm
廣告

© . All rights reserved.