22 Iterators library [iterators]

22.4 Iterator primitives [iterator.primitives]

22.4.3 Range iterator operations [range.iter.ops]

22.4.3.2 ranges​::​distance [range.iter.op.distance]

template<Iterator I, Sentinel<I> S> constexpr iter_difference_t<I> ranges::distance(I first, S last);
Expects: [first, last) denotes a range, or [last, first) denotes a range and S and I model Same<S, I> && SizedSentinel<S, I>.
Effects: If S and I model SizedSentinel<S, I>, returns (last - first); otherwise, returns the number of increments needed to get from first to last.
template<Range R> constexpr iter_difference_t<iterator_t<R>> ranges::distance(R&& r);
Effects: If R models SizedRange, equivalent to:
return ranges::size(r);                                         // [range.prim.size]
Otherwise, equivalent to:
return ranges::distance(ranges::begin(r), ranges::end(r));      // [range.access]