◆ remove_if() [3/4]

template<typename DerivedPolicy , typename ForwardIterator , typename InputIterator , typename Predicate >
__host__ __device__ ForwardIterator thrust::remove_if ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
InputIterator  stencil,
Predicate  pred 

remove_if removes from the range [first, last) every element x such that pred(x) is true. That is, remove_if returns an iterator new_last such that the range [first, new_last) contains no elements for which pred of the corresponding stencil value is true. The iterators in the range [new_last,last) are all still dereferenceable, but the elements that they point to are unspecified. remove_if is stable, meaning that the relative order of elements that are not removed is unchanged.

The algorithm's execution is parallelized as determined by exec.

execThe execution policy to use for parallelization.
firstThe beginning of the range of interest.
lastThe end of the range of interest.
stencilThe beginning of the stencil sequence.
predA predicate to evaluate for each element of the range [stencil, stencil + (last - first)). Elements for which pred evaluates to true are removed from the sequence [first, last)
A ForwardIterator pointing to the end of the resulting range of elements for which pred evaluated to true.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator and ForwardIterator is mutable.
InputIteratoris a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type.
Predicateis a model of Predicate.
The range [first, last) shall not overlap the range [result, result + (last - first)).
The range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)).

The following code snippet demonstrates how to use remove_if to remove specific elements from an array of integers using the thrust::host execution policy for parallelization:

#include <thrust/remove.h>
const int N = 6;
int A[N] = {1, 4, 2, 8, 5, 7};
int S[N] = {0, 1, 1, 1, 0, 0};
int *new_end = thrust::remove_if(thrust::host, A, A + N, S, thrust::identity<int>());
// The first three values of A are now {1, 5, 7}
// Values beyond new_end are unspecified
The range [first, last) is not permitted to overlap with the range [stencil, stencil + (last - first)).
See also