public member function
<set>

std::multiset::upper_bound

iterator upper_bound (const value_type& val) const;
const_iterator upper_bound (const value_type& val) const;
      iterator upper_bound (const value_type& val);
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 multiset 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 multiset contains elements equivalent to val: In this case lower_bound returns an iterator pointing to the first of such elements, whereas upper_bound returns an iterator pointing to the element following the last.

Parameters

val
Value to compare.
Member type value_type is the type of the elements in the container, defined in multiset 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 multiset::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
// multiset::lower_bound/upper_bound
#include <iostream>
#include <set>

int main ()
{
  std::multiset<int> mymultiset;
  std::multiset<int>::iterator itlow,itup;

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

  itlow = mymultiset.lower_bound (30);             //       ^
  itup = mymultiset.upper_bound (40);              //             ^

  mymultiset.erase(itlow,itup);                    // 10 20 50 60 70

  std::cout << "mymultiset contains:";
  for (std::multiset<int>::iterator it=mymultiset.begin(); it!=mymultiset.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.
mymultiset contains: 10 20 50 60 70

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 multiset 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