Template Function thrust::distance¶
Defined in File distance.h
Function Documentation¶
-
template<typename InputIterator>__host__ __device__ thrust::iterator_traits<InputIterator>::difference_type thrust::distance(InputIterator first, InputIterator last) distancefinds the distance betweenfirstandlast, i.e. the number of times thatfirstmust be incremented until it is equal tolast.The following code snippet demonstrates how to use
distanceto compute the distance to one iterator from another.- Return
The distance between the beginning and end of the input range.
- Pre
If
InputIteratormeets the requirements of random access iterator,lastshall be reachable fromfirstorfirstshall be reachable fromlast; otherwise,lastshall be reachable fromfirst.- Parameters
first: The beginning of an input range of interest.last: The end of an input range of interest.
- Template Parameters
InputIterator: is a model of Input Iterator.
#include <thrust/distance.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> vec(13); thrust::device_vector<int>::iterator iter1 = vec.begin(); thrust::device_vector<int>::iterator iter2 = iter1 + 7; int d = thrust::distance(iter1, iter2); // d is 7