The erase–remove idiom is a common C++ technique to eliminate elements that fulfill a certain criterion from a C++ Standard Library container.
Calling erase multiple times on the same container generates much overhead from moving the elements.
Because these algorithms operate on a range of elements denoted by two forward iterators, they have no knowledge of the underlying container or collection.
remove returns an iterator pointing to the first of these tail elements so that they can be deleted using a single call to erase.
These convenience functions can be used to perform correct erasure of elements without requiring the programmer to explicitly use the erase-remove idiom.