Template Function thrust::copy(InputIterator, InputIterator, OutputIterator)¶
Function Documentation¶
-
template<typename
InputIterator
, typenameOutputIterator
>
OutputIteratorthrust
::
copy
(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 integern
from0
tolast
-first
,copy
performs the assignment *(result
+n
) = *(first
+n
). Unlikestd::copy
,copy
offers no guarantee on order of operation. As a result, callingcopy
with overlapping source and destination ranges has undefined behavior.The return value is
result
+ (last
-first
).The following code snippet demonstrates how to use
copy
to copy from one range to another.- Return
The end of the destination sequence.
- See
- Pre
result
may be equal tofirst
, butresult
shall not be in the range[first, last)
otherwise.- Parameters
first
: The beginning of the sequence to copy.last
: The end of the sequence to copy.result
: The destination sequence.
- Template Parameters
InputIterator
: must be a model of Input Iterator andInputIterator's
value_type
must be convertible toOutputIterator's
value_type
.OutputIterator
: must be a model of Output Iterator.
#include <thrust/copy.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> vec0(100); thrust::device_vector<int> vec1(100); ... thrust::copy(vec0.begin(), vec0.end(), vec1.begin()); // vec1 is now a copy of vec0