std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::count
Min standard notice:
- Returns the number of elements with key that compares equal to the specified argument key.
# Declarations
size_type count( const Key& key ) const;
(since C++11)
template< class K >
size_type count( const K& x ) const;
(since C++20)
# Parameters
key: key value of the elements to countx: a value of any type that can be transparently compared with a key
# Notes
Feature-test macro Value Std Feature __cpp_lib_generic_unordered_lookup 201811L (C++20) Heterogeneous comparison lookup in unordered associative containers, overload (2)
# Example
#include <algorithm>
#include <iostream>
#include <unordered_set>
int main()
{
std::unordered_multiset set{2, 7, 1, 8, 2, 8, 1, 8, 2, 8};
std::cout << "The set is:\n";
for (int e : set)
std::cout << e << ' ';
const auto [min, max] = std::ranges::minmax(set);
std::cout << "\nNumbers [" << min << ".." << max << "] frequency:\n";
for (int i{min}; i <= max; ++i)
std::cout << i << ':' << set.count(i) << "; ";
std::cout << '\n';
}