std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::size - cppreference.com
来自cppreference.com
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); }