thrust

◆ copy() [1/2]

template<typename DerivedPolicy , typename InputIterator , typename OutputIterator >
__host__ __device__ OutputIterator thrust::copy ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
OutputIterator  result 
)

copy copies elements from the range [first, last) to the range [result, result + (last - first)). That is, it performs the assignments *result = *first, *(result + 1) = *(first + 1), and so on. Generally, for every integer n from 0 to last - first, copy performs the assignment *(result + n) = *(first + n). Unlike std::copy, copy offers no guarantee on order of operation. As a result, calling copy with overlapping source and destination ranges has undefined behavior.

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

The algorithm's execution is parallelized as determined by exec.

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence to copy.
lastThe end of the sequence to copy.
resultThe destination sequence.
Returns
The end of the destination sequence.
See also
http://www.sgi.com/tech/stl/copy.html
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratormust be a model of Input Iterator and InputIterator's value_type must be convertible to OutputIterator's value_type.
OutputIteratormust be a model of Output Iterator.
Precondition
result may be equal to first, but result shall not be in the range [first, last) otherwise.

The following code snippet demonstrates how to use copy to copy from one range to another using the thrust::device parallelization policy:

#include <thrust/copy.h>
...
thrust::device_vector<int> vec0(100);
...
thrust::copy(thrust::device, vec0.begin(), vec0.end(), vec1.begin());
// vec1 is now a copy of vec0