Javatpoint Logo
Javatpoint Logo

C++ Multiset lower_bound()

C++ Multiset lower_bound() function is used to return an iterator pointing to the key in the multiset container which is equivalent to val passed in the parameter.

If val is not present in the multiset container, it returns an iterator pointing to the immediate next element which is just greater than val.

Syntax

Parameter

val: Value to be searched in the multiset container.

Return value

It returns an iterator pointing to the value in the multiset container which is equivalent to val passed in the parameter. If there is no such element return end().

Complexity

Logarithmic in size.

Iterator validity

No changes.

Data Races

The container is accessed (neither the const nor the non-const versions modify the multiset).

Concurrently accessing the elements of container is safe.

Exception Safety

If an exception is thrown, there are no changes in the multiset.

Example 1

Let's see the simple example to get the lower bound of given key:

Output:

Lower bound(=) of c is: c

In the above example, lower bound of c is c.

Example 2

Let's see a simple example to erase the element of multiset from lower bound to upper bound:

Output:

mymultiset contains: 10 20 70 80 90

In the above example, erase() function erased the element of multiset from lower bound(=) to upper bound(>) and print the remaining content.

Example 3

Let's see a simple example:

Output:

The element of multiset s1 with a key of 20 is: 20.
The multiset s1 doesn't have an element with a key of 40.
The element of s1 with a key matching that of the last element is: 30.

Example 4

Let's see a simple example:

Output:

Elements are: 
1
2
4
5
The lower bound of key 2 is 2
The lower bound of key 3 is 4
The lower bound of key 6 is 4

In the above example, when we try to find the lower bound of a value which exceeds the container or we can say that which is not present in the multiset container then it will return to the end .

Next TopicC++ multiset





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA