Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ multiset::lower_bound function is used to return an iterator pointing to the first element in the multiset container which is not considered to go before the specified value (it could be either same or goes after the specified value). If all elements of the multiset are considered to go before the specified value, then the iterator points to multiset::end.

Syntax

iterator lower_bound (const value_type& val) const;
iterator lower_bound (const value_type& val);
const_iterator lower_bound (const value_type& val) const;

Parameters

val Specify value to compare.

Return Value

An iterator pointing to the first element in the multiset container which is not considered to go before the specified value, or multiset::end if all elements of the multiset is considered to go before the specified value.

Time Complexity

Logarithmic i.e, Θ(log(n))

Example:

In the below example, the multiset::lower_bound function is used with multiset::upper_bound to specify the lower and upper bound in the multiset called MyMSet.

#include <iostream>
#include <set>
using namespace std;
 
int main (){
  multiset<int> MyMSet{10, 20, 30, 40, 40, 50, 50, 60, 70, 80};
  multiset<int>::iterator it, itlower, itupper;

  itlower = MyMSet.lower_bound(25);
  itupper = MyMSet.upper_bound(50);
  MyMSet.erase(itlower, itupper);

  cout<<"MyMSet contains: ";
  for(it = MyMSet.begin(); it != MyMSet.end(); ++it)
    cout<<" "<<*it;

  return 0;
}

The output of the above code will be:

MyMSet contains:  10 20 60 70 80

❮ C++ - Multiset