名稱空間
變體
操作

std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::size

來自 cppreference.com
< cpp‎ | 容器‎ | 無序對映
 
 
 
 
size_type size() const noexcept;
(C++11 起)

返回容器中的元素數量,即 std::distance(begin(), end())

目錄

[編輯] 返回值

容器中的元素數量。

[編輯] 複雜度

常數時間。

[編輯] 示例

#include <cassert>
#include <unordered_map>
 
int main()
{
    std::unordered_map<int, char> nums{{1, 'a'}, {1, 'b'}, {2, 'c'}, {2, 'd'}};
    assert(nums.size() == 2); 
}

[編輯] 另請參閱

檢查容器是否為空
(public member function) [edit]
返回元素的最大可能數量
(public member function) [edit]
(C++17)(C++20)
返回容器或陣列的大小
(function template) [edit]