std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::size
從 cppreference.com
< cpp | container | unordered map
size_type size() const noexcept; |
(C++11 起) (C++26 起為 constexpr) |
|
返回容器中的元素數。
目錄 |
[編輯] 返回值
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); }
[編輯] 參閱
檢查容器是否為空 (公開成員函數) | |
返回可容納的最大元素數 (公開成員函數) | |
(C++17)(C++20) |
返回容器或數組的大小 (函數模板) |