public member function
<set>

std::multiset::find

iterator find (const value_type& val) const;
const_iterator find (const value_type& val) const;iterator       find (const value_type& val);
Get iterator to element
Searches the container for an element equivalent to val and returns an iterator to it if found, otherwise it returns an iterator to multiset::end.

Notice that this function returns an iterator to a single element (of the possibly multiple equivalent elements). To obtain the entire range of equivalent elements, see multiset::equal_range.

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 be searched for.
成員型別value_typeis the type of the elements in the container, defined in multiset as an alias of its first template parameter (T).

返回值

An iterator to the element, if val is found, or multiset::end otherwise.

成員型別iteratorconst_iteratorare bidirectional iterator types pointing to elements.

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// multiset::find
#include <iostream>
#include <set>

int main ()
{
  std::multiset<int> mymultiset;
  std::multiset<int>::iterator it;

  // set some initial values:
  for (int i=1; i<=5; i++) mymultiset.insert(i*10);   // 10 20 30 40 50

  it=mymultiset.find(20);
  mymultiset.erase (it);
  mymultiset.erase (mymultiset.find(40));

  std::cout << "mymultiset contains:";
  for (it=mymultiset.begin(); it!=mymultiset.end(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}

輸出
mymultiset contains: 10 30 50


複雜度

Logarithmic in size.

迭代器有效性

沒有變化。

資料競爭

訪問容器(const 和非 const 版本都不會修改容器)。
同時訪問 multiset 的元素是安全的。

異常安全

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

另見