Template Function thrust::swap_ranges(ForwardIterator1, ForwardIterator1, ForwardIterator2)¶
Function Documentation¶
-
template<typename
ForwardIterator1, typenameForwardIterator2>
ForwardIterator2thrust::swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2) swap_rangesswaps each of the elements in the range[first1, last1)with the corresponding element in the range[first2, first2 + (last1 - first1)). That is, for each integernsuch that0 <= n < (last1 - first1), it swaps*(first1 + n)and*(first2 + n). The return value isfirst2 + (last1 - first1).The following code snippet demonstrates how to use
swap_rangesto swap the contents of twothrust::device_vectors.- Return
An iterator pointing to one position past the last element of the second sequence to swap.
- Pre
first1may equalfirst2, but the range[first1, last1)shall not overlap the range[first2, first2 + (last1 - first1))otherwise.- Parameters
first1: The beginning of the first sequence to swap.last1: One position past the last element of the first sequence to swap.first2: The beginning of the second sequence to swap.
- Template Parameters
ForwardIterator1: is a model of Forward Iterator, andForwardIterator1'svalue_typemust be convertible toForwardIterator2'svalue_type.ForwardIterator2: is a model of Forward Iterator, andForwardIterator2'svalue_typemust be convertible toForwardIterator1'svalue_type.
#include <thrust/swap.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> v1(2), v2(2); v1[0] = 1; v1[1] = 2; v2[0] = 3; v2[1] = 4; thrust::swap_ranges(v1.begin(), v1.end(), v2.begin()); // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2
- See
- See
swap