Files
cppdraft_translate/cppdraft/range/sized.md
2025-10-25 03:02:53 +03:00

3.2 KiB
Raw Blame History

[range.sized]

25 Ranges library [ranges]

25.4 Range requirements [range.req]

25.4.4 Sized ranges [range.sized]

1

#

The sized_range concept refines approximately_sized_range with the requirement that the number of elements in the range can be determined in amortized constant time using ranges::size.

🔗

template<class T> concept [sized_range](#concept:sized_range "25.4.4Sized ranges[range.sized]") = [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]")<T> && requires(T& t) { ranges::size(t); };

2

#

Given an lvalue t of type remove_reference_t, T models sized_range only if

ranges::size(t) is amortized O(1), does not modify t, and is equal to ranges::distance(ranges::begin(t), ranges::end(t)), and

if iterator_t models forward_iterator,ranges::size(t) is well-defined regardless of the evaluation ofranges::begin(t). [Note 1: ranges::size(t) is otherwise not required to be well-defined after evaluating ranges::begin(t). For example, it is possible for ranges::size(t) to be well-defined for a sized_range whose iterator type does not model forward_iterator only if evaluated before the first call to ranges::begin(t). — end note]

🔗

template<class> constexpr bool disable_sized_range = false;

3

#

Remarks: Pursuant to [namespace.std], users may specialize disable_sized_range for cv-unqualified program-defined types.

Such specializations shall be usable in constant expressions ([expr.const]) and have type const bool.

4

#

[Note 2:

disable_sized_range allows use of range types with the library that satisfy but do not in fact model sized_range.

— end note]