74
76
/*! \addtogroup copying
78
/*! \p swap_ranges swaps each of the elements in the range <tt>[first1, last1)</tt>
79
* with the corresponding element in the range <tt>[first2, first2 + (last1 - first1))</tt>.
80
* That is, for each integer \c n such that <tt>0 <= n < (last1 - first1)</tt>, it swaps
81
* <tt>*(first1 + n)</tt> and <tt>*(first2 + n)</tt>. The return value is
82
* <tt>first2 + (last1 - first1)</tt>.
84
* \param first1 The beginning of the first sequence to swap.
85
* \param last1 One position past the last element of the first sequence to swap.
86
* \param first2 The beginning of the second sequence to swap.
87
* \return An iterator pointing to one position past the last element of the second
90
* \tparam ForwardIterator1 is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
91
* and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type.
92
* \tparam ForwardIterator2 is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
93
* and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type.
81
/*! \p swap_ranges swaps each of the elements in the range <tt>[first1, last1)</tt>
82
* with the corresponding element in the range <tt>[first2, first2 + (last1 - first1))</tt>.
83
* That is, for each integer \c n such that <tt>0 <= n < (last1 - first1)</tt>, it swaps
84
* <tt>*(first1 + n)</tt> and <tt>*(first2 + n)</tt>. The return value is
85
* <tt>first2 + (last1 - first1)</tt>.
87
* The algorithm's execution is parallelized as determined by \p exec.
89
* \param exec The execution policy to use for parallelization.
90
* \param first1 The beginning of the first sequence to swap.
91
* \param last1 One position past the last element of the first sequence to swap.
92
* \param first2 The beginning of the second sequence to swap.
93
* \return An iterator pointing to one position past the last element of the second
96
* \tparam DerivedPolicy The name of the derived execution policy.
97
* \tparam ForwardIterator1 is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
98
* and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type.
99
* \tparam ForwardIterator2 is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
100
* and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type.
102
* \pre \p first1 may equal \p first2, but the range <tt>[first1, last1)</tt> shall not overlap the range <tt>[first2, first2 + (last1 - first1))</tt> otherwise.
104
* The following code snippet demonstrates how to use \p swap_ranges to
105
* swap the contents of two \c thrust::device_vectors using the \p thrust::device execution
106
* policy for parallelization:
109
* #include <thrust/swap.h>
110
* #include <thrust/device_vector.h>
111
* #include <thrust/execution_policy.h>
113
* thrust::device_vector<int> v1(2), v2(2);
119
* thrust::swap_ranges(thrust::device, v1.begin(), v1.end(), v2.begin());
121
* // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2
124
* \see http://www.sgi.com/tech/stl/swap_ranges.html
127
template<typename DerivedPolicy,
128
typename ForwardIterator1,
129
typename ForwardIterator2>
130
ForwardIterator2 swap_ranges(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
131
ForwardIterator1 first1,
132
ForwardIterator1 last1,
133
ForwardIterator2 first2);
136
/*! \p swap_ranges swaps each of the elements in the range <tt>[first1, last1)</tt>
137
* with the corresponding element in the range <tt>[first2, first2 + (last1 - first1))</tt>.
138
* That is, for each integer \c n such that <tt>0 <= n < (last1 - first1)</tt>, it swaps
139
* <tt>*(first1 + n)</tt> and <tt>*(first2 + n)</tt>. The return value is
140
* <tt>first2 + (last1 - first1)</tt>.
142
* \param first1 The beginning of the first sequence to swap.
143
* \param last1 One position past the last element of the first sequence to swap.
144
* \param first2 The beginning of the second sequence to swap.
145
* \return An iterator pointing to one position past the last element of the second
148
* \tparam ForwardIterator1 is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
149
* and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type.
150
* \tparam ForwardIterator2 is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
151
* and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type.
153
* \pre \p first1 may equal \p first2, but the range <tt>[first1, last1)</tt> shall not overlap the range <tt>[first2, first2 + (last1 - first1))</tt> otherwise.
95
155
* The following code snippet demonstrates how to use \p swap_ranges to
96
156
* swap the contents of two \c thrust::device_vectors.