lower_bound returns the minimum position in a sorted vector that an element can be inserted, without losing the sorted order property. upper_bound, the maximum. With this in mind, is there any edge case for which:
auto lower = std::lower_bound(vec.begin(), vec.end(), x);
auto upper = std::upper_bound(lower, vec.end(), y); // using lower, as opposed to vec.begin()
for (auto it = lower; it != upper; it++) { /* do work */ }
Would not perform as expected? That is, would not visit every element in the range [x, y), where x < y?
I wish to know if this optimization (albeit small) is actually viable.