Daily bit(e) of C++ | std::counted_iterator
Daily bit(e) of C++ ♻️92, Specifying ranges using a begin iterator and the number of elements with std::counted_iterator.
A couple of algorithms in the standard library provide a counted variant, a variant in which the range is specified using a begin iterator and the number of elements.
C++20 introduced the std::counted_iterator adapter that can turn any algorithm into a counted variant.