thrust

◆ reverse_copy() [2/2]

template<typename BidirectionalIterator , typename OutputIterator >
OutputIterator thrust::reverse_copy ( BidirectionalIterator  first,
BidirectionalIterator  last,
OutputIterator  result 
)

reverse_copy differs from reverse only in that the reversed range is written to a different output range, rather than inplace.

reverse_copy copies elements from the range [first, last) to the range [result, result + (last - first)) such that the copy is a reverse of the original range. Specifically: for every i such that 0 <= i < (last - first), reverse_copy performs the assignment *(result + (last - first) - i) = *(first + i).

The return value is result + (last - first)).

Parameters
firstThe beginning of the range to reverse.
lastThe end of the range to reverse.
resultThe beginning of the output range.
Template Parameters
BidirectionalIteratoris a model of Bidirectional Iterator, and BidirectionalIterator's value_type is convertible to OutputIterator's value_type.
OutputIteratoris a model of Output Iterator.
Precondition
The range [first, last) and the range [result, result + (last - first)) shall not overlap.

The following code snippet demonstrates how to use reverse_copy to reverse an input device_vector of integers to an output device_vector.

#include <thrust/reverse.h>
...
const int N = 6;
int data[N] = {0, 1, 2, 3, 4, 5};
thrust::device_vector<int> input(data, data + N);
thrust::reverse_copy(v.begin(), v.end(), output.begin());
// input is still {0, 1, 2, 3, 4, 5}
// output is now {5, 4, 3, 2, 1, 0}
See also
http://www.sgi.com/tech/stl/reverse_copy.html
reverse
reverse_iterator