A RetroSearch Logo

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

Search Query:

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

public member function

<set>

std::set::upper_bound
iterator upper_bound (const value_type& val) const;
      iterator upper_bound (const value_type& val);const_iterator upper_bound (const value_type& val) const;

Return iterator to upper bound

Returns an iterator pointing to the first element in the container which is considered to go after val.

The function uses its internal comparison object (key_comp) to determine this, returning an iterator to the first element for which key_comp(val,element) would return true.

If the set class is instantiated with the default comparison type (less), the function returns an iterator to the first element that is greater than val.

A similar member function, lower_bound, has the same behavior as upper_bound, except in the case that the set contains an element equivalent to val: In this case lower_bound returns an iterator pointing to that element, whereas upper_bound returns an iterator pointing to the next element.



Parameters
val
Value to compare.
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 the first element in the container which is considered to go after val, or set::end if no elements are considered to go after val.

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

int main ()
{
  std::set<int> myset;
  std::set<int>::iterator itlow,itup;

  for (int i=1; i<10; i++) myset.insert(i*10); // 10 20 30 40 50 60 70 80 90

  itlow=myset.lower_bound (30);                //       ^
  itup=myset.upper_bound (60);                 //                   ^

  myset.erase(itlow,itup);                     // 10 20 70 80 90

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

  return 0;
}

Notice that lower_bound(30) returns an iterator to 30, whereas upper_bound(60) returns an iterator to 70.
myset contains: 10 20 70 80 90


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::lower_bound
Return iterator to lower bound (public member function)
set::equal_range
Get range of equal elements (public member function)
set::find
Get iterator to element (public member function)
set::count
Count elements with a specific value (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