I understand that container::lower_bound
harness helpful invariant of the very container hence gives a better performance than std::lower_bound
.
Taking std::set::lower_bound
as an example, during my own development I found it's about O(logN) as expected for bisection, while std::lower_bound
on the same set object deteriorates and the cost falls back to linear time.
I wonder does it mean we should always prefer the lower_bound()
or upper_bound()
offered by the standard container if there is one? any tradeoff?