Template Function thrust::copy_n(InputIterator, Size, OutputIterator)

Function Documentation

template<typename InputIterator, typename Size, typename OutputIterator>
OutputIterator thrust::copy_n(InputIterator first, Size n, OutputIterator result)

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

The return value is result + n.

The following code snippet demonstrates how to use

copy to copy from one range to another.
Return

The end of the destination range.

Pre

result may be equal to first, but result shall not be in the range [first, first + n) otherwise.

Parameters
  • first: The beginning of the range to copy.

  • n: The number of elements to copy.

  • result: The beginning destination range.

Template Parameters
  • InputIterator: must be a model of Input Iterator and InputIterator's value_type must be convertible to OutputIterator's value_type.

  • Size: is an integral type.

  • OutputIterator: must be a model of Output Iterator.

#include <thrust/copy.h>
#include <thrust/device_vector.h>
...
size_t n = 100;
thrust::device_vector<int> vec0(n);
thrust::device_vector<int> vec1(n);
...
thrust::copy_n(vec0.begin(), n, vec1.begin());

// vec1 is now a copy of vec0

See

http://www.sgi.com/tech/stl/copy_n.html

See

thrust::copy