25 Iterators library [iterators]

25.4 Iterator primitives [iterator.primitives]

25.4.4 Range iterator operations [range.iter.ops] ranges​::​distance [range.iter.op.distance]

template<input_­or_­output_­iterator I, sentinel_­for<I> S> requires (!sized_­sentinel_­for<S, I>) constexpr iter_difference_t<I> ranges::distance(I first, S last);
Preconditions: [first, last) denotes a range.
Effects: Increments first until last is reached and returns the number of increments.
template<input_­or_­output_­iterator I, sized_­sentinel_­for<I> S> constexpr iter_difference_t<I> ranges::distance(const I& first, const S& last);
Effects: Equivalent to: return last - first;
template<range R> constexpr range_difference_t<R> ranges::distance(R&& r);
Effects: If R models sized_­range, equivalent to: return static_cast<range_difference_t<R>>(ranges::size(r)); // [range.prim.size]
Otherwise, equivalent to: return ranges::distance(ranges::begin(r), ranges::end(r)); // [range.access]