public member function
<set>

std::set::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 set::end.

Two elements of a set 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 be searched for.
Member type value_type is the type of the elements in the container, defined in set as an alias of its first template parameter (T).

Return value

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

Member types iterator and const_iterator are bidirectional iterator types pointing to elements.

Example

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

int main ()
{
  std::set<int> myset;
  std::set<int>::iterator it;

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

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

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

  return 0;
}


Output:
myset contains: 10 30 50

Complexity

Logarithmic in size.

Iterator validity

No changes.

Data races

The container is accessed (neither the const nor the non-const versions modify the container).
Concurrently accessing the elements of a set is safe.

Exception safety

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

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