Most of the list-specific algorithms are similar—but not identical—to their generic counterparts. However, a crucially important difference between the list-specific and the generic versions is that the list versions change the underlying container. For example, the list version of remove
removes the indicated elements. The list version of unique
removes the second and subsequent duplicate elements.
Similarly, merge
and splice
are destructive on their arguments. For example, the generic version of merge
writes the merged sequence to a given destination iterator; the two input sequences are unchanged. The list merge
function destroys the given list—elements are removed from the argument list as they are merged into the object on which merge
was called. After a merge
, the elements from both lists continue to exist, but they are all elements of the same list.