Thrust
|
#include <thrust/iterator/reverse_iterator.h>
Public Member Functions | |
__host__ __device__ | reverse_iterator () |
__host__ __device__ | reverse_iterator (BidirectionalIterator x) |
template<typename OtherBidirectionalIterator > | |
__host__ __device__ | reverse_iterator (reverse_iterator< OtherBidirectionalIterator > const &r) |
reverse_iterator
is an iterator which represents a pointer into a reversed view of a given range. In this way, reverse_iterator
allows backwards iteration through a bidirectional input range.
It is important to note that although reverse_iterator
is constructed from a given iterator, it points to the element preceding it. In this way, the past-the-end reverse_iterator
of a given range points to the element preceding the first element of the input range. By the same token, the first reverse_iterator
of a given range is constructed from a past-the-end iterator of the original range yet points to the last element of the input.
The following code snippet demonstrates how to create a reverse_iterator
which represents a reversed view of the contents of a device_vector
.
Since reversing a range is a common operation, containers like device_vector
have nested typedefs for declaration shorthand and methods for constructing reverse_iterators. The following code snippet is equivalent to the previous:
Finally, the following code snippet demonstrates how to use reverse_iterator to perform a reversed prefix sum operation on the contents of a device_vector: