thrust::stable_partition
Defined in thrust/partition.h
- 
template<typename ForwardIterator, typename Predicate>
 ForwardIterator thrust::stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred)
- stable_partitionis much like- partition: it reorders the elements in the range- [first, last)based on the function object- pred, such that all of the elements that satisfy- predprecede all of the elements that fail to satisfy it. The postcondition is that, for some iterator- middlein the range- [first, last),- pred(*i)is- truefor every iterator- iin the range- [first,middle)and- falsefor every iterator- iin the range- [middle, last). The return value of- stable_partitionis- middle.- stable_partitiondiffers from- partitionin that- stable_partitionis guaranteed to preserve relative order. That is, if- xand- yare elements in- [first, last), and- stencil_xand- stencil_yare the stencil elements in corresponding positions within- [stencil, stencil + (last - first)), and- pred(stencil_x) == pred(stencil_y), and if- xprecedes- y, then it will still be true after- stable_partitionthat- xprecedes- y.- The following code snippet demonstrates how to use - stable_partitionto reorder a sequence so that even numbers precede odd numbers.- #include <thrust/partition.h> ... struct is_even { __host__ __device__ bool operator()(const int &x) { return (x % 2) == 0; } }; ... int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int N = sizeof(A)/sizeof(int); thrust::stable_partition(A, A + N, is_even()); // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} - See also - partition- See also - stable_partition_copy- Parameters
- first – The first element of the sequence to reorder. 
- last – One position past the last element of the sequence to reorder. 
- pred – A function object which decides to which partition each element of the sequence - [first, last)belongs.
 
- Template Parameters
- ForwardIterator – is a model of Forward Iterator, and - ForwardIterator's- value_typeis convertible to- Predicate'sargument type, and- ForwardIteratoris mutable.
- Predicate – is a model of Predicate. 
 
- Returns
- An iterator referring to the first element of the second partition, that is, the sequence of the elements which do not satisfy pred.