thrust::reverse
Defined in thrust/reverse.h
-
template<typename DerivedPolicy, typename BidirectionalIterator>
void thrust::reverse(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, BidirectionalIterator first, BidirectionalIterator last) reversereverses a range. That is: for everyisuch that0 <= i <= (last - first) / 2, it exchanges*(first + i)and*(last - (i + 1)).The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
reverseto reverse adevice_vectorof integers using thethrust::deviceexecution policy for parallelization:#include <thrust/reverse.h> #include <thrust/execution_policy.h> ... const int N = 6; int data[N] = {0, 1, 2, 3, 4, 5}; thrust::device_vector<int> v(data, data + N); thrust::reverse(thrust::device, v.begin(), v.end()); // v is now {5, 4, 3, 2, 1, 0}
See also
reverse_copySee also
- Parameters
exec – The execution policy to use for parallelization.
first – The beginning of the range to reverse.
last – The end of the range to reverse.
- Template Parameters
DerivedPolicy – The name of the derived execution policy.
BidirectionalIterator – is a model of Bidirectional Iterator and
BidirectionalIteratoris mutable.