remove


Remove all matching items from a sequence.

Remove all occurrences of value from the sequence [ first ... last ). Return an iterator equal to last - n , where n equals the number of elements removed. The size of the container is not altered. If n elements are removed, the last n elements of the sequence [ first ... last ) have undefined values.

Library

Standards<ToolKit>

Declaration


#include <algorithm>

template< class ForwardIterator, class T >
ForwardIterator remove
  (
  ForwardIterator first,
  ForwardIterator last,
  const T& value
  );
  

Complexity

Time complexity is linear, as ( last - first ) comparisons are performed. Space complexity is constant.

Example <ospace/osstd/examples/remove1.cpp>
#include <iostream>
#include <algorithm>

int numbers[ 6 ] = { 1, 2, 3, 1, 2, 3 };

void
main()
  {
  remove( numbers, numbers + 6, 1 );

  for ( int i = 0; i < 6; ++i )
    cout << numbers[ i ] << ` `;
  cout << "\n";
  }

2 3 2 3 2 3

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.