public member function
<set>

std::multiset::count

size_type count (const value_type& val) const;
Count elements with a specific key
Searches the container for elements equivalent to val and returns the number of matches.

Two elements of a multiset are considered equivalent if the container's comparison object returns false reflexively (i.e., no matter the order in which the elements are passed as arguments).

Parameters

val
Value to search for.
Member type value_type is the type of the elements in the container, defined in multiset as an alias of its first template parameter (T).

Return value

The number of elements in the container that are equivalent to val.

Member type size_type is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
// multiset::count
#include <iostream>
#include <set>

int main ()
{
  int myints[]={10,73,12,22,73,73,12};
  std::multiset<int> mymultiset (myints,myints+7);

  std::cout << "73 appears " << mymultiset.count(73) << " times in mymultiset.\n";

  return 0;
}


Output:
73 appears 3 times in mymultiset.

Complexity

Logarithmic in size and linear in the number of matches.

Iterator validity

No changes.

Data races

The container is accessed.
Concurrently accessing the elements of a multiset is safe.

Exception safety

Strong guarantee: if an exception is thrown, there are no changes in the container.

See also

  • 9316991614 2018-02-25
  • 191841613 2018-02-25
  • 16411612 2018-02-25
  • 6081981611 2018-02-25
  • 1784561610 2018-02-25
  • 4651609 2018-02-25
  • 9348111608 2018-02-25
  • 2513771607 2018-02-25
  • 6478461606 2018-02-24
  • 4985791605 2018-02-24
  • 5637141604 2018-02-24
  • 282181603 2018-02-24
  • 6217941602 2018-02-24
  • 5076141601 2018-02-24
  • 714281600 2018-02-24
  • 6607141599 2018-02-24
  • 949041598 2018-02-24
  • 6809961597 2018-02-24
  • 671871596 2018-02-24
  • 7107821595 2018-02-24