public member function
<set>

std::multiset::count

size_type count (const value_type& val) const;
計算具有特定鍵的元素
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 returnsfalsereflexively (i.e., no matter the order in which the elements are passed as arguments).

引數

val
Value to search for.
成員型別value_typeis the type of the elements in the container, defined in multiset as an alias of its first template parameter (T).

返回值

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

成員型別size_type是一種無符號整型型別。

示例

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;
}

輸出
73 appears 3 times in mymultiset.


複雜度

Logarithmic in size and linear in the number of matches.

迭代器有效性

沒有變化。

資料競爭

訪問容器。
同時訪問 multiset 的元素是安全的。

異常安全

強保證:如果丟擲異常,容器沒有發生變化。

另見