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
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