當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ Unordered_map unordered_map()用法及代碼示例


描述

C++ 函數std::unordered_map::unordered_map()構造一個具有零元素的空 unordered_map。

聲明

以下是 std::unordered_map::unordered_map() 函數形式 std::unordered_map 頭文件的聲明。

C++11

explicit unordered_map(size_type n = /* implementation defined */,
                       const hasher& hf = hasher(),
                       const key_equal& eql = key_equal(),
                       const allocator_type& alloc = allocator_type()
                      );

參數

  • n− 初始桶的最大數量。

  • hf- 要使用的哈希函數。

  • eql- 如果提供的兩個容器對象被認為是相等的,則比較函數對象返回 true。

  • alloc- 用於此容器的所有內存分配的分配器。

返回值

構造函數從不返回值。

時間複雜度

常數,即 O(1)

示例

下麵的例子展示了 std::unordered_map::unordered_map() 函數的用法。

#include <iostream>
#include <unordered_map>

using namespace std;

int main(void) {
   unordered_map<char, int> um;

   cout << "Size of unordered_map = " << um.size() << endl;

   return 0;
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

Size of unordered_map = 0

相關用法


注:本文由純淨天空篩選整理自 C++ Unordered_map Library - unordered_map() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。