Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
multiset
comparison operators
multiset::multiset
multiset::~multiset
member functions:
multiset::begin
multiset::clear
multiset::count
multiset::empty
multiset::end
multiset::equal_range
multiset::erase
multiset::find
multiset::get_allocator
multiset::insert
multiset::key_comp
multiset::lower_bound
multiset::max_size
multiset::operator=
multiset::rbegin
multiset::rend
multiset::size
multiset::swap
multiset::upper_bound
multiset::value_comp


multiset::upper_bound

public member function
iterator upper_bound ( const key_type& x ) const;

Return iterator to upper bound

Returns an iterator pointing to the first element in the container which compares greater than x (using the container's comparison object).

Unlike lower_bound, this member function does not return an iterator to the element if it compares equal to x, but only if it compares strictly greater.

Notice that, internally, all the elements in a multiset container are always ordered following the criterion defined by its comparison object, therefore all the elements that follow the one returned by this function will compare greater than x.

Parameters

x
Key value to be compared.
key_type is a member type defined in multiset containers as an alias of Key, which is the first template parameter and the type of the elements stored in the container.

Return value

An iterator to the the first element in the container which compares greater than x.
iterator is a member type, defined in multiset as a bidirectional iterator type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// multiset::lower_bound/upper_bound
#include <iostream>
#include <set>
using namespace std;
int main ()
{
  multiset<int> mymultiset;
  multiset<int>::iterator it,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
  cout << "mymultiset contains:";
  for (it=mymultiset.begin(); it!=mymultiset.end(); it++)
    cout << " " << *it;
  cout << endl;
  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.

See also