This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++23 status.
sized_range is circularSection: 25.4.4 [range.sized] Status: C++23 Submitter: Tim Song Opened: 2021-06-03 Last modified: 2023-11-22
Priority: Not Prioritized
View all other issues in [range.sized].
View all issues with C++23 status.
Discussion:
25.4.4 [range.sized] p2.1 requires that for a sized_range t, ranges::size(t)
is equal to ranges::distance(t). But for a sized_range, ranges::distance(t)
is simply ranges::size(t) cast to the difference type.
distance(begin, end) — the actual distance you get
from traversing the range — is equal to what ranges::size produces, and not merely that
casting from the size type to difference type is value-preserving. Otherwise, sized_range would
be more or less meaningless.
[2021-06-14; Reflector poll]
Set status to Tentatively Ready after seven votes in favour during reflector poll.
[2021-10-14 Approved at October 2021 virtual plenary. Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4885.
Modify 25.4.4 [range.sized] as indicated:
template<class T> concept sized_range = range<T> && requires(T& t) { ranges::size(t); };-2- Given an lvalue
tof typeremove_reference_t<T>,Tmodelssized_rangeonly if
(2.1) —
ranges::size(t)is amortized 𝒪(1), does not modifyt, and is equal toranges::distance(ranges::begin(t), ranges::end(t), andt)(2.2) — if
iterator_t<T>modelsforward_iterator,ranges::size(t)is well-defined regardless of the evaluation ofranges::begin(t).