Template Function thrust::remove_if(ForwardIterator, ForwardIterator, InputIterator, Predicate)¶
Function Documentation¶
-
template<typename
ForwardIterator, typenameInputIterator, typenamePredicate>
ForwardIteratorthrust::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.- Return
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)).- 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 andForwardIteratoris mutable.InputIterator: is a model of Input Iterator, andInputIterator'svalue_typeis convertible toPredicate'sargument_type.Predicate: is a model of Predicate.
#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
- Note
The range
[first, last)is not permitted to overlap with the range[stencil, stencil + (last - first)).- See
- See
remove
- See
remove_copy
- See
remove_copy_if