Is the behavior for passing an empty container to
I checked cppreference.com and an old version of the C++ standard that I found online, but couldn't find a definite answer.
The cppreference.com documentation for
std::deque::erase has a sentence
The iterator first does not need to be dereferenceable if
first==last: erasing an empty range is a no-op.
I miss something like this for
std::lower_bound and other algorithms.
Cppreference on the return value of
"[it returns] Iterator pointing to the first element that is not less than value, or
lastif no such element is found.".
In an empty range, there will be no elements that satisfy the criteria, so
last will be returned.
Concluding from this, applying
std::lower_bound (and similar) on the empty range is well-defined. It does nothing and returns
last, which is equal to