remove_copy |
Copy a sequence, removing all matching items.
Copy the sequence [ first ... last ) to a sequence starting at result , skipping any occurrences of value . Return an iterator positioned immediately after the last new element.
#include <algorithm>
template< class InputIterator, class OutputIterator, class T >
OutputIterator remove_copy
(
InputIterator first,
InputIterator last,
OutputIterator result,
const T& value
);
Time complexity is linear, as (
last - first )
comparisons are performed. Space complexity is constant.
#include <iostream>
#include <algorithm>
int numbers[ 6 ] = { 1, 2, 3, 1, 2, 3 };
int result[ 6 ] = { 0, 0, 0, 0, 0, 0 };
void
main()
{
remove_copy( numbers, numbers + 6, result, 2 );
for ( int i = 0; i < 6; ++i )
cout << result[ i ] << ` `;
cout << "\n";
}
1 3 1 3 0 0
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.