Template Function thrust::advance¶
Defined in File advance.h
Function Documentation¶
-
template<typename InputIterator, typename Distance>__host__ __device__ void thrust::advance(InputIterator & i, Distance n)
advance(i, n)
increments the iteratori
by the distancen
. Ifn > 0
it is equivalent to executing++i
n
times, and ifn < 0
it is equivalent to executingi
n
times. Ifn == 0
, the call has no effect.The following code snippet demonstrates how to use
advance
to increment an iterator a given number of times.- Pre
n
shall be negative only for bidirectional and random access iterators.- Parameters
i
: The iterator to be advanced.n
: The distance by which to advance the iterator.
- Template Parameters
InputIterator
: is a model of Input Iterator.Distance
: is an integral type that is convertible toInputIterator's
distance type.
#include <thrust/advance.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> vec(13); thrust::device_vector<int>::iterator iter = vec.begin(); thrust::advance(iter, 7); // iter - vec.begin() == 7