is_sorted
#
Overloads#
is_sorted(exec, first, last)
#
-
template<typename DerivedPolicy, typename ForwardIterator>
bool thrust::is_sorted( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
is_sorted
returnstrue
if the range[first, last)
is sorted in ascending order, andfalse
otherwise.Specifically, this version of
is_sorted
returnsfalse
if for some iteratori
in the range[first, last - 1)
the expression*(i + 1) < *i
istrue
.The algorithm’s execution is parallelized as determined by
exec
.The following code demonstrates how to use
is_sorted
to test whether the contents of adevice_vector
are stored in ascending order using thethrust::device
execution policy for parallelization:#include <thrust/sort.h> #include <thrust/device_vector.h> #include <thrust/sort.h> #include <thrust/execution_policy.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; bool result = thrust::is_sorted(thrust::device, v.begin(), v.end()); // result == false thrust::sort(v.begin(), v.end()); result = thrust::is_sorted(thrust::device, v.begin(), v.end()); // result == true
See also
See also
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator,
ForwardIterator's
value_type
is a model of LessThan Comparable, and the ordering on objects ofForwardIterator's
value_type
is a strict weak ordering, as defined in the LessThan Comparable requirements.
- Returns:
true
, if the sequence is sorted;false
, otherwise.
is_sorted(first, last)
#
-
template<typename ForwardIterator>
bool thrust::is_sorted( - ForwardIterator first,
- ForwardIterator last,
is_sorted
returnstrue
if the range[first, last)
is sorted in ascending order, andfalse
otherwise.Specifically, this version of
is_sorted
returnsfalse
if for some iteratori
in the range[first, last - 1)
the expression*(i + 1) < *i
istrue
.The following code demonstrates how to use
is_sorted
to test whether the contents of adevice_vector
are stored in ascending order.#include <thrust/sort.h> #include <thrust/device_vector.h> #include <thrust/sort.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; bool result = thrust::is_sorted(v.begin(), v.end()); // result == false thrust::sort(v.begin(), v.end()); result = thrust::is_sorted(v.begin(), v.end()); // result == true
See also
See also
See also
See also
- Parameters:
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator,
ForwardIterator's
value_type
is a model of LessThan Comparable, and the ordering on objects ofForwardIterator's
value_type
is a strict weak ordering, as defined in the LessThan Comparable requirements.- Returns:
true
, if the sequence is sorted;false
, otherwise.
is_sorted(exec, first, last, comp)
#
-
template<typename DerivedPolicy, typename ForwardIterator, typename Compare>
bool thrust::is_sorted( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- Compare comp,
is_sorted
returnstrue
if the range[first, last)
is sorted in ascending order according to a user-defined comparison operation, andfalse
otherwise.Specifically, this version of
is_sorted
returnsfalse
if for some iteratori
in the range[first, last - 1)
the expressioncomp(*(i + 1), *i)
istrue
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
is_sorted
to test whether the contents of adevice_vector
are stored in descending order using thethrust::device
execution policy for parallelization:#include <thrust/sort.h> #include <thrust/functional.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.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; ::cuda::std::greater<int> comp; bool result = thrust::is_sorted(thrust::device, v.begin(), v.end(), comp); // result == false thrust::sort(v.begin(), v.end(), comp); result = thrust::is_sorted(thrust::device, v.begin(), v.end(), comp); // result == true
See also
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
comp – Comparison operator.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator's
value_type
is convertible to bothStrictWeakOrdering's
first and second argument type.Compare – is a model of Strict Weak Ordering.
- Returns:
true
, if the sequence is sorted according to comp;false
, otherwise.
is_sorted(first, last, comp)
#
-
template<typename ForwardIterator, typename Compare>
bool thrust::is_sorted( - ForwardIterator first,
- ForwardIterator last,
- Compare comp,
is_sorted
returnstrue
if the range[first, last)
is sorted in ascending order according to a user-defined comparison operation, andfalse
otherwise.Specifically, this version of
is_sorted
returnsfalse
if for some iteratori
in the range[first, last - 1)
the expressioncomp(*(i + 1), *i)
istrue
.The following code snippet demonstrates how to use
is_sorted
to test whether the contents of adevice_vector
are stored in descending order.#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; ::cuda::std::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 also
See also
See also
- 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, and
ForwardIterator's
value_type
is convertible to bothStrictWeakOrdering's
first and second argument type.Compare – is a model of Strict Weak Ordering.
- Returns:
true
, if the sequence is sorted according to comp;false
, otherwise.