Why are we subtracting 1 from lb even after using comparator function?
Use of comparator function
@Senjuti256 if you observe carefully you will see that lower_bound when used with comparator function will always return the index of key which has value greater than the value to be found. Hence we will have to subtract 1 from index in order to get the index of key which has value smaller than or equal to the required value.
But by using comparator function we have overwritten the functionality of the default lower_bound function to return the value less than or equal to the key value that is here money.So what is the need to subtract 1 and how can we subtract a integer from pointers or addresses?
deafult comparator of lower bound is return a<b which return value greater than or equal to key value. here we are returning a<=b means return value strictly greater than key value.
we are not subtracting 1 from pointer or address, we have already subtracted coins which makes it int then subtract -1.
if the default comparator of lower bound is a less than b then how does it return value greater than or equal to the key value?
return a<b means it will reject the values which are less than key value and hence will give you the first value which is not less than ( greater than or equal to) key value.
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.