thrust::remove_if

Defined in thrust/remove.h

template<typename ForwardIterator, typename InputIterator, typename Predicate>
ForwardIterator thrust::remove_if(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 following code snippet demonstrates how to use remove_if to remove specific elements from an array of integers.

#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(A, A + N, S, thrust::identity<int>());
// The first three values of A are now {1, 5, 7}
// Values beyond new_end are unspecified

See also

remove

See also

remove_copy

See also

remove_copy_if

Note

The range [first, last) is not permitted to overlap with the range [stencil, stencil + (last - first)).

Parameters
  • first – The beginning of the range of interest.

  • last – The end of the range of interest.

  • stencil – The beginning of the stencil sequence.

  • pred – A 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)

Template Parameters
  • ForwardIterator – is a model of Forward Iterator and ForwardIterator is mutable.

  • InputIterator – is a model of Input Iterator, and InputIterator's value_type is convertible to Predicate's argument_type.

  • Predicate – is a model of Predicate.

Returns

A ForwardIterator pointing to the end of the resulting range of elements for which pred evaluated to true.

Pre

The range [first, last) shall not overlap the range [result, result + (last - first)).

Pre

The range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first)).