◆ remove_copy_if() [2/4]

template<typename InputIterator , typename OutputIterator , typename Predicate >
OutputIterator thrust::remove_copy_if ( InputIterator  first,
InputIterator  last,
OutputIterator  result,
Predicate  pred 

remove_copy_if copies elements from the range [first,last) to a range beginning at result, except that elements for which pred is true are not copied. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as the range [first,last).

firstThe beginning of the range of interest.
lastThe end of the range of interest.
resultThe resulting range is copied to the sequence beginning at this location.
predA predicate to evaluate for each element of the range [first,last). Elements for which pred evaluates to false are not copied to the resulting sequence.
An OutputIterator pointing to the end of the resulting range.
Template Parameters
InputIteratoris a model of Input Iterator, InputIterator's value_type is convertible to a type in OutputIterator's set of value_types, and InputIterator's value_type is convertible to Predicate's argument_type.
OutputIteratoris a model of Output Iterator.
Predicateis a model of Predicate.
The range [first, last) shall not overlap the range [result, result + (last - first)).

The following code snippet demonstrates how to use remove_copy_if to copy a sequence of numbers to an output range while omitting even numbers.

#include <thrust/remove.h>
struct is_even
__host__ __device__
bool operator()(const int x)
return (x % 2) == 0;
const int N = 6;
int V[N] = {-2, 0, -1, 0, 1, 2};
int result[2];
thrust::remove_copy_if(V, V + N, result, is_even());
// V remains {-2, 0, -1, 0, 1, 2}
// result is now {-1, 1}
See also