2 * Copyright 2008-2013 NVIDIA Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * \brief Advance an iterator by a given distance.
24 #include <thrust/detail/config.h>
30 /*! \addtogroup iterators
34 /*! \p advance(i, n) increments the iterator \p i by the distance \p n.
35 * If <tt>n > 0</tt> it is equivalent to executing <tt>++i</tt> \p n
36 * times, and if <tt>n < 0</tt> it is equivalent to executing <tt>--i</tt>
37 * \p n times. If <tt>n == 0</tt>, the call has no effect.
39 * \param i The iterator to be advanced.
40 * \param n The distance by which to advance the iterator.
42 * \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
43 * \tparam Distance is an integral type that is convertible to \p InputIterator's distance type.
45 * \pre \p n shall be negative only for bidirectional and random access iterators.
47 * The following code snippet demonstrates how to use \p advance to increment
48 * an iterator a given number of times.
51 * #include <thrust/advance.h>
52 * #include <thrust/device_vector.h>
54 * thrust::device_vector<int> vec(13);
55 * thrust::device_vector<int>::iterator iter = vec.begin();
57 * thrust::advance(iter, 7);
59 * // iter - vec.begin() == 7
62 * \see http://www.sgi.com/tech/stl/advance.html
64 template <typename InputIterator, typename Distance>
65 void advance(InputIterator& i, Distance n);
67 /*! \} // end iterators
72 #include <thrust/detail/advance.inl>