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 的元素是安全的。

异常安全

强保证:如果抛出异常,容器没有发生变化。

另见