Is there a function in that uses binary search, like lower_bound
but that returns the last item less-than-or-equal-to according to a given predic
In a sorted container, the last element that is less than or equivalent to x
, is the element before the first element that is greater than x
.
Thus you can call std::upper_bound
, and decrement the returned iterator once.
(Before decrementing, you must of course check that it is not the begin iterator; if it is, then there are no elements that are less than or equivalent to x
.)