Template Function thrust::remove_copy_if(InputIterator, InputIterator, OutputIterator, Predicate)¶
Function Documentation¶
-
template<typename
InputIterator, typenameOutputIterator, typenamePredicate>
OutputIteratorthrust::remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred) remove_copy_ifcopies elements from the range[first,last)to a range beginning atresult, except that elements for whichpredistrueare 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).The following code snippet demonstrates how to use
remove_copy_ifto copy a sequence of numbers to an output range while omitting even numbers.- Return
An OutputIterator pointing to the end of the resulting range.
- Pre
The range
[first, last)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.result: The resulting range is copied to the sequence beginning at this location.pred: A predicate to evaluate for each element of the range[first,last). Elements for whichpredevaluates tofalseare not copied to the resulting sequence.
- Template Parameters
InputIterator: is a model of Input Iterator,InputIterator'svalue_typeis convertible to a type inOutputIterator'sset ofvalue_types, andInputIterator'svalue_typeis convertible toPredicate'sargument_type.OutputIterator: is a model of Output Iterator.Predicate: is a model of Predicate.
#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
- See
remove
- See
remove_copy
- See
remove_if