~ubuntu-branches/ubuntu/utopic/libthrust/utopic

« back to all changes in this revision

Viewing changes to swap.h

  • Committer: Package Import Robot
  • Author(s): Andreas Beckmann
  • Date: 2013-07-10 12:57:33 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130710125733-my19jic71sqsabaj
Tags: 1.7.0-1
* New upstream release.  (Closes: #715362)
* Update watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#pragma once
22
22
 
23
23
#include <thrust/detail/config.h>
 
24
#include <thrust/detail/execution_policy.h>
24
25
 
25
26
// empty Doxygen comment below so namespace thrust's documentation will be extracted
26
27
 
71
72
/*! \} // utility
72
73
 */
73
74
 
 
75
 
74
76
/*! \addtogroup copying
75
77
 *  \{
76
78
 */
77
79
 
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>.
83
 
 *
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
88
 
 *          sequence to swap.
89
 
 *
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.
 
80
 
 
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>.
 
86
 *
 
87
 *  The algorithm's execution is parallelized as determined by \p exec.
 
88
 *
 
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
 
94
 *          sequence to swap.
 
95
 *
 
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.
 
101
 *
 
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.
 
103
 *
 
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:
 
107
 *
 
108
 *  \code
 
109
 *  #include <thrust/swap.h>
 
110
 *  #include <thrust/device_vector.h>
 
111
 *  #include <thrust/execution_policy.h>
 
112
 *  ...
 
113
 *  thrust::device_vector<int> v1(2), v2(2);
 
114
 *  v1[0] = 1;
 
115
 *  v1[1] = 2;
 
116
 *  v2[0] = 3;
 
117
 *  v2[1] = 4;
 
118
 *
 
119
 *  thrust::swap_ranges(thrust::device, v1.begin(), v1.end(), v2.begin());
 
120
 *
 
121
 *  // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2
 
122
 *  \endcode
 
123
 *
 
124
 *  \see http://www.sgi.com/tech/stl/swap_ranges.html
 
125
 *  \see \c swap
 
126
 */
 
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);
 
134
 
 
135
 
 
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>.
 
141
 *
 
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
 
146
 *          sequence to swap.
 
147
 *
 
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.
 
152
 *
 
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.
94
154
 *
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.
119
179
                               ForwardIterator1 last1,
120
180
                               ForwardIterator2 first2);
121
181
 
 
182
 
122
183
/*! \} // copying
123
184
 */
124
185
 
 
186
 
125
187
} // end thrust
126
188
 
127
189
#include <thrust/detail/swap.inl>