distance

template<class Init, class Dist>
    typename iterator_traits<InIt>::difference_type
        distance(InIt first, InIt last);

The template function sets a count n to zero. It then effectively advances first and increments n until first == last. If InIt is a random-access iterator type, the function evaluates the expression n += last - first. Otherwise, it performs each iterator increment by evaluating ++first.