Javatpoint Logo
Javatpoint Logo

C++ Multiset equal_range()

C++ Multiset equal_range() function is used to return the boundary of the range containing all elements in the container that are equal to val.

If val does not match any value in the container, the return value range will be length 0 and both iterators will point to the nearest value greater than val. Otherwise, if val is greater than all elements in the container, it points to end.

Syntax

The range is defined by two iterators, one points to the first element that is not less than value val and another points to the first element greater than value val.

Parameter

val: value to be searched in the multiset container.

Return value

This function returns pair. Where pair:: first is at the lower boundary of the range with the same value that lower_bound (val) would return, pair :: second is the same value as the upper_bound (val) would return, upper bound of the range it corresponds to.

Complexity

Logarithmic in size.

Iterator validity

No changes.

Data Races

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

Concurrently accessing the elements of a multiset is safe.

Exception Safety

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

Example 1

Let's see the simple example:

Output:

Lower bound of b is: b
Upper bound of b is: c

In the above example, lower bound of b is b and upper bound of b is c.

Example 2

Let's see a simple example:

Output:

The lower bound is 3
The upper bound is 3

In the above example, equal_range() function returns to the end() i.e. 3 because it tries to find 10 which is not present in the multiset mp therefore, it returns to the end.

Example 3

Let's see a simple example:

Output:

The upper bound of the element with a key of 20 in the multiset s1 is: 30.
The lower bound of the element with a key of 20 in the multiset s1 is: 20.
A direct call of upper_bound( 20 ) gives 30,
matching the 2nd element of the pair returned by equal_range( 20 ).
The multiset s1 doesn't have an element with a key less than 40.

Example 4

Let?s see a simple example:

Output:

the lower bound points to: 30
the upper bound points to: 40
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