Javatpoint Logo
Javatpoint Logo

C++ set lower_bound()

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

If val is not present in the set 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 set container.

Return value

It returns an iterator pointing to the value in the set 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 container).

Concurrently accessing the elements of a set is safe.

Exception Safety

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

Example 1

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

Output:

Lower bound 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 set from lower bound to upper bound:

Output:

myset contains: 10 20 70 80 90

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

Example 3

Let's see a simple example:

Output:

The element of set s1 with a key of 20 is: 20.
The set 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 set container then it will return to the end .






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA