thrust::copy_n#
Overloads#
copy_n(exec, first, n, result)#
-
template<typename DerivedPolicy, typename InputIterator, typename Size, typename OutputIterator>
OutputIterator thrust::copy_n( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- Size n,
- OutputIterator result,
copy_ncopies 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 integerifrom0ton,copyperforms the assignment *(resulti) = *(first+i). Unlikestd::copy_n,copy_noffers no guarantee on order of operation. As a result, callingcopy_nwith overlapping source and destination ranges has undefined behavior.The return value is
result+n.The algorithm’s execution is parallelized as determined by
exec.
The following code snippet demonstrates how to use
copyto copy from one range to another using thethrust::deviceparallelization policy:#include <thrust/copy.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... size_t n = 100; thrust::device_vector<int> vec0(n); thrust::device_vector<int> vec1(n); ... thrust::copy_n(thrust::device, vec0.begin(), n, vec1.begin()); // vec1 is now a copy of vec0
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the range to copy.
n – The number of elements to copy.
result – The beginning destination range.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – must be a model of Input Iterator and
InputIterator'svalue_typemust be convertible toOutputIterator'svalue_type.Size – is an integral type.
OutputIterator – must be a model of Output Iterator.
- Returns:
The end of the destination range.
- Pre:
resultmay be equal tofirst, butresultshall not be in the range[first, first + n)otherwise.
copy_n(first, n, result)#
-
template<typename InputIterator, typename Size, typename OutputIterator>
OutputIterator thrust::copy_n( - InputIterator first,
- Size n,
- OutputIterator result,
copy_ncopies 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 integerifrom0ton,copyperforms the assignment *(resulti) = *(first+i). Unlikestd::copy_n,copy_noffers no guarantee on order of operation. As a result, callingcopy_nwith overlapping source and destination ranges has undefined behavior.The return value is
result+n.
The following code snippet demonstrates how to use
copyto copy from one range to another.#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 also
- 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'svalue_typemust be convertible toOutputIterator'svalue_type.Size – is an integral type.
OutputIterator – must be a model of Output Iterator.
- Returns:
The end of the destination range.
- Pre:
resultmay be equal tofirst, butresultshall not be in the range[first, first + n)otherwise.