remove_copy_if |
Copy a sequence, removing all items that satisfy a predicate.
Copy the sequence [ first ... last ) to a sequence starting at result , skipping any elements that satisfy pred . Return an iterator positioned immediately after the last new element.
#include <algorithm>
template< class InputIterator, class OutputIterator, class Predicate >
OutputIterator remove_copy_if
(
InputIterator first,
InputIterator last,
OutputIterator result,
Predicate pred
);
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 };
bool
odd( int a_ )
{
return a_ % 2;
}
void
main()
{
remove_copy_if( numbers, numbers + 6, result, odd );
for ( int i = 0; i < 6; ++i )
cout << result[ i ] << ` `;
cout << "\n";
}
2 2 0 0 0 0
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.