◆ distance()

template<typename InputIterator >
__host__ __device__ thrust::iterator_traits<InputIterator>::difference_type thrust::distance ( InputIterator  first,
InputIterator  last 

distance finds the distance between first and last, i.e. the number of times that first must be incremented until it is equal to last.

firstThe beginning of an input range of interest.
lastThe end of an input range of interest.
The distance between the beginning and end of the input range.
Template Parameters
InputIteratoris a model of Input Iterator.
If InputIterator meets the requirements of random access iterator, last shall be reachable from first or first shall be reachable from last; otherwise, last shall be reachable from first.

The following code snippet demonstrates how to use distance to compute the distance to one iterator from another.

thrust::device_vector<int> vec(13);
int d = thrust::distance(iter1, iter2);
// d is 7
See also