Template Function thrust::is_sorted(ForwardIterator, ForwardIterator, Compare)¶
Function Documentation¶
-
template<typename
ForwardIterator, typenameCompare>
boolthrust::is_sorted(ForwardIterator first, ForwardIterator last, Compare comp) is_sortedreturnstrueif the range[first, last)is sorted in ascending order accoring to a user-defined comparison operation, andfalseotherwise.Specifically, this version of
is_sortedreturnsfalseif for some iteratoriin the range[first, last - 1)the expressioncomp(*(i + 1), *i)istrue.The following code snippet demonstrates how to use
is_sortedto test whether the contents of adevice_vectorare stored in descending order.- Return
true, if the sequence is sorted according to comp;false, otherwise.- Parameters
first: The beginning of the sequence.last: The end of the sequence.comp: Comparison operator.
- Template Parameters
ForwardIterator: is a model of Forward Iterator, andForwardIterator'svalue_typeis convertible to bothStrictWeakOrdering'sfirst_argument_typeandsecond_argument_type.Compare: is a model of Strict Weak Ordering.
#include <thrust/sort.h> #include <thrust/functional.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> v(6); v[0] = 1; v[1] = 4; v[2] = 2; v[3] = 8; v[4] = 5; v[5] = 7; thrust::greater<int> comp; bool result = thrust::is_sorted(v.begin(), v.end(), comp); // result == false thrust::sort(v.begin(), v.end(), comp); result = thrust::is_sorted(v.begin(), v.end(), comp); // result == true
- See
- See
sort- See
stable_sort- See
less<T>