public member function
<unordered_map>

std::unordered_multimap::count

size_type count ( const key_type& k ) const;
Count elements with a specific key
Searches the container for elements whose key is k and returns the number of elements found.

Parameters

k
Key value to be searched for.
Member type key_type is the type of the keys for the elements in the container, defined in unordered_multimap as an alias of its first template parameter (Key).

Return value

The number of elements in the container with a key equivalent to k.

Member type size_type is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// unordered_multimap::count
#include <iostream>
#include <string>
#include <unordered_map>

int main ()
{
  std::unordered_multimap<std::string,std::string> myumm = {
     {"orange","FL"},
     {"strawberry","LA"},
     {"strawberry","OK"},
     {"pumpkin","NH"} };

  for (auto& x: {"orange","lemon","strawberry"}) {
    std::cout << x << ": " << myumm.count(x) << " entries.\n";
  }

  return 0;
}


Output:
orange: 1 entries.
lemon: 0 entries.
strawberry: 2 entries.

Complexity

Average case: linear in the number of elements counted.
Worst case: linear in container size.

Iterator validity

No changes.

See also