std::unordered_multimap<Key,T,Hash,KeyEqual,Allocator>::count

  1. 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

# 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 <iostream>
#include <string>
#include <unordered_map>
 
int main()
{
    std::unordered_multimap<int, std::string> dict = {
        {1, "one"}, {6, "six"}, {3, "three"}
    };
    dict.insert({4, "four"});
    dict.insert({5, "five"});
    dict.insert({6, "six"});
 
    std::cout << "dict: { ";
    for (auto const& [key, value] : dict)
        std::cout << '[' << key << "]=" << value << ' ';
    std::cout << "}\n\n";
 
    for (int i{1}; i != 8; ++i)
        std::cout << "dict.count(" << i << ") = " << dict.count(i) << '\n';
}

# See also