thrust::swap_ranges#
Overloads#
swap_ranges(exec, first1, last1, first2)#
-
template<typename DerivedPolicy, typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator2 thrust::swap_ranges( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- 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 algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
swap_rangesto swap the contents of twothrust::device_vectorsusing thethrust::deviceexecution policy for parallelization:#include <thrust/swap.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... thrust::device_vector<int> v1(2), v2(2); v1[0] = 1; v1[1] = 2; v2[0] = 3; v2[1] = 4; thrust::swap_ranges(thrust::device, v1.begin(), v1.end(), v2.begin()); // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2
See also
- Parameters:
exec – The execution policy to use for parallelization.
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:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator1 – is a model of Forward Iterator, and
ForwardIterator1'svalue_typemust be convertible toForwardIterator2'svalue_type.ForwardIterator2 – is a model of Forward Iterator, and
ForwardIterator2'svalue_typemust be convertible toForwardIterator1'svalue_type.
- Returns:
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.
swap_ranges(first1, last1, first2)#
-
template<typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator2 thrust::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.#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 also
- 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, and
ForwardIterator1'svalue_typemust be convertible toForwardIterator2'svalue_type.ForwardIterator2 – is a model of Forward Iterator, and
ForwardIterator2'svalue_typemust be convertible toForwardIterator1'svalue_type.
- Returns:
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.