Why does c++ have functions for "STRICTLY GREATER OR EQUAL NUMBER" but not "STRICTLY LESSER"?

Like we have “upper_bound” function for strictly greater and “lower_bound” for strictly equal or greater. But why don’t we have inbuilt function to find strictly lower number?

Thank you.
Peace! :slight_smile:

The position right before a lower_bound call, if it exists, will always be strictly less. So it’s not necessary.

3 Likes

I think you can eventually derive other functions using these two functions. Check this.
PS : If you find anything incorrect please reply here.

How much time the lower_bound takes to find the number strictly less than key ?

lowerbound takes O(lgn) time. So, you can use lowerbound to find number strictly less than the number by moving one iterator back.

@initish How to get lowerbound value index ?

subtract vector.begin()

Caution:   Don’t blindly subtract numbers/ iterators from other iterators. Calculations like vec.end( ) - vec.begin( ) work with vector but not with set/ multiset as they have different types of iterators. Google about it, to learn more.

1 Like