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

  • 9281021542 2018-02-20
  • 632231541 2018-02-20
  • 9751491540 2018-02-20
  • 8333621539 2018-02-20
  • 995001538 2018-02-20
  • 6477441537 2018-02-20
  • 511981536 2018-02-19
  • 2072881535 2018-02-19
  • 6024461534 2018-02-19
  • 7594061533 2018-02-19
  • 9311341532 2018-02-19
  • 4928331531 2018-02-19
  • 38561530 2018-02-19
  • 7776611529 2018-02-19
  • 3038041528 2018-02-19
  • 9566341527 2018-02-19
  • 3936031526 2018-02-19
  • 9531111525 2018-02-19
  • 291211524 2018-02-19
  • 8962001523 2018-02-19