24 Ranges library [ranges]

24.4 Range requirements [range.req]

24.4.3 Sized ranges [range.sized]

The sized_­range concept refines 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 = range<T> && requires(T& t) { ranges::size(t); };
Given an lvalue t of type remove_­reference_­t<T>, T models sized_­range only if
  • ranges​::​size(t) is amortized , does not modify t, and is equal to ranges​::​distance(t), and
  • if iterator_­t<T> models forward_­iterator, 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 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> inline constexpr bool disable_sized_range = false;
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.
[Note
:
disable_­sized_­range allows use of range types with the library that satisfy but do not in fact model sized_­range.
— end note
]