thrust::partition
Defined in thrust/partition.h
-
template<typename ForwardIterator, typename InputIterator, typename Predicate>
ForwardIterator thrust::partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred) partition
reorders the elements[first, last)
based on the function objectpred
applied to a stencil range[stencil, stencil + (last - first))
, such that all of the elements whose corresponding stencil element satisfiespred
precede all of the elements whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iteratormiddle
in the range[first, last)
,pred(*stencil_i)
istrue
for every iteratorstencil_i
in the range[stencil,stencil + (middle - first))
andfalse
for every iteratorstencil_i
in the range[stencil
The following code snippet demonstrates how to use to reorder a sequence so that even numbers precede odd numbers.