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_ifremoves from the range[first, last)every elementxsuch thatpred(x)istrue. That is,remove_ifreturns an iteratornew_lastsuch that the range[first, new_last)contains no elements for whichpredof the corresponding stencil value istrue. The iterators in the range[new_last,last)are all still dereferenceable, but the elements that they point to are unspecified.remove_ifis stable, meaning that the relative order of elements that are not removed is unchanged.The following code snippet demonstrates how to use
remove_ifto 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, ::cuda::std::identity{}); // 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 whichpredevaluates totrueare removed from the sequence[first, last)
- Template Parameters
ForwardIterator – is a model of Forward Iterator and
ForwardIteratoris mutable.InputIterator – is a model of Input Iterator, and
InputIterator'svalue_typeis convertible toPredicate'sargument type.Predicate – is a model of Predicate.
- Returns
A ForwardIterator pointing to the end of the resulting range of elements for which
predevaluated totrue.- 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)).