A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/set/set/equal_range/ below:

public member function

<set>

std::set::equal_range
pair<iterator,iterator> equal_range (const value_type& val) const;
pair<const_iterator,const_iterator> equal_range (const value_type& val) const;pair<iterator,iterator>             equal_range (const value_type& val);

Get range of equal elements

Returns the bounds of a range that includes all the elements in the container that are equivalent to val.

Because all elements in a set container are unique, the range returned will contain a single element at most.

If no matches are found, the range returned has a length of zero, with both iterators pointing to the first element that is considered to go after val according to the container's internal comparison object (key_comp).

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 search 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 The function returns a pair, whose member pair::first is the lower bound of the range (the same as lower_bound), and pair::second is the upper bound (the same as upper_bound).

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
// set::equal_elements
#include <iostream>
#include <set>

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

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

  std::pair<std::set<int>::const_iterator,std::set<int>::const_iterator> ret;
  ret = myset.equal_range(30);

  std::cout << "the lower bound points to: " << *ret.first << '\n';
  std::cout << "the upper bound points to: " << *ret.second << '\n';

  return 0;
}

the lower bound points to: 30
the upper bound points to: 40


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 safetyStrong guarantee: if an exception is thrown, there are no changes in the container.

See also
set::count
Count elements with a specific value (public member function)
set::lower_bound
Return iterator to lower bound (public member function)
set::upper_bound
Return iterator to upper bound (public member function)
set::find
Get iterator to element (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4