thrust

◆ advance()

template<typename InputIterator , typename Distance >
__host__ __device__ void thrust::advance ( InputIterator &  i,
Distance  n 
)

advance(i, n) increments the iterator i by the distance n. If n > 0 it is equivalent to executing ++i n times, and if n < 0 it is equivalent to executing –i n times. If n == 0, the call has no effect.

Parameters
iThe iterator to be advanced.
nThe distance by which to advance the iterator.
Template Parameters
InputIteratoris a model of Input Iterator.
Distanceis an integral type that is convertible to InputIterator's distance type.
Precondition
n shall be negative only for bidirectional and random access iterators.

The following code snippet demonstrates how to use advance to increment an iterator a given number of times.

#include <thrust/advance.h>
...
thrust::device_vector<int> vec(13);
thrust::advance(iter, 7);
// iter - vec.begin() == 7
See also
http://www.sgi.com/tech/stl/advance.html

Referenced by thrust::iterator_adaptor< Derived, Base, Value, System, Traversal, Reference, Difference >::base_reference(), thrust::iterator_facade< Derived, Value, System, Traversal, Reference, Difference >::operator+=(), thrust::iterator_facade< Derived, Value, System, Traversal, Reference, Difference >::operator-=(), and thrust::reverse_iterator< BidirectionalIterator >::reverse_iterator().