Regarding -1 done in lb

why -1 is done in the lb bound when we have changed the compare function and what is this compare function actually doing

@sharad1103 the compare functions gives you the first value that is GREATER than the key, that’s why you have to do -1 in the iterator.

without compare function also the lower bound gives the index of greater or equal number?

use of compare is to give only greater number not equal??

1 Like

Yes you got that right

than why are we doing a<=b in compare it would return the last number that is less than or equal to key

then why are we doing a<=b in compare it would return the last number that is less than or equal to key how will it return the greater one?

what is the actual compare code of default lower_bound function?

@sharad1103 that compare function ensures that equal values are passed as well and only a > b returns false, so that the first element to fail the condition a <= b is returned. It is basically converted to the upper_bound function.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.