24 Ranges library [ranges]

24.4 Range requirements [range.req]

24.4.3 Sized ranges [range.sized]

The SizedRange concept specifies the requirements of a Range type that knows its size in constant time with the size function.
template<class T> concept SizedRange = Range<T> && !disable_sized_range<remove_cvref_t<T>> && requires(T& t) { ranges::size(t); };
Given an lvalue t of type remove_­reference_­t<T>, T models SizedRange only if
  • ranges::size(t) is , does not modify t, and is equal to ranges::distance(t), and
  • if iterator_­t<T> models ForwardIterator, ranges::size(t) is well-defined regardless of the evaluation of ranges::begin(t).
    [Note
    :
    ranges::size(t) is otherwise not required to be well-defined after evaluating ranges::begin(t).
    For example, ranges::size(t) might be well-defined for a SizedRange whose iterator type does not model ForwardIterator only if evaluated before the first call to ranges::begin(t).
    end note
    ]
[Note
:
The complexity requirement for the evaluation of ranges::size is non-amortized, unlike the case for the complexity of the evaluations of ranges::begin and ranges::end in the Range concept.
end note
]
[Note
:
disable_­sized_­range allows use of range types with the library that satisfy but do not in fact model SizedRange.
end note
]