The std::remove and std::remove_if compact a range so that the leading sub-range [begin, last) does not contain any elements that match the provided value or for which the predicate evaluates to true.
The number of elements in the range is unaffected, the non-removed elements maintain their relative order and the subrange [last, end) contains elements in a moved-from state.
Compiler Explorer link: https://compiler-explorer.com/z/65zoKv7c1
From cppreference:
**
Relative order of the elements that remain is preserved and the physical size of the container is unchanged. Iterators pointing to an element between the new logical end and the physical end of the range are still dereferenceable, but the elements themselves have unspecified values (as per MoveAssignable post-condition) (since C++11).
**
Doesn't the last sentence say the state of the [last, end) is invalid, i.e., unusable? That they are in a "moved-from state"?
@rmerriam @simontoth
logically you have to consider the being 'moved from', because you only reasonably can destroy them or re-assign. technically, they might still have their original value.
moved-from state is overloaded, it can mean
a) you don't know what state an object has after an operation: 'valid but unspecified'
b) you are talking about a manager type object (such as unique_ptr or vector), where the state after being moved from is empty.