Skip to content

[range.approximately.sized] Move to before [range.sized] #7807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions source/ranges.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1146,46 +1146,6 @@
its type is integer-like.
\end{note}

\rSec2[range.approximately.sized]{Approximately sized ranges}

\pnum
The \libconcept{approximately_sized_range} concept refines \libconcept{range}
with the requirement that
an approximation of the number of elements in the range
can be determined in amortized constant time using \tcode{ranges::reserve_hint}.

\begin{itemdecl}
template<class T>
concept @\deflibconcept{approximately_sized_range}@ =
@\libconcept{range}@<T> && requires(T& t) { ranges::reserve_hint(t); };
\end{itemdecl}

\begin{itemdescr}
\pnum
Given an lvalue \tcode{t} of type \tcode{remove_reference_t<T>},
\tcode{T} models \libconcept{approximately_sized_range} only if
\begin{itemize}
\item
\tcode{ranges::reserve_hint(t)} is amortized \bigoh{1},
does not modify \tcode{t}, and
has a value that
is not negative and is representable in \tcode{range_difference_t<T>}, and
\item
if \tcode{iterator_t<T>} models \libconcept{forward_iterator},
\tcode{ranges::reserve_hint(t)} is well-defined
regardless of the evaluation of \tcode{ranges::begin(t)}.
\begin{note}
\tcode{ranges::reserve_hint(t)} is otherwise not required to be well-defined
after evaluating \tcode{ranges::\linebreak begin(t)}.
For example,
it is possible for \tcode{ranges::reserve_hint(t)} to be well-defined for
an \libconceptx{approximate\-ly_sized_range}{approximately_sized_range} whose
iterator type does not model \libconcept{forward_iterator}
only if evaluated before the first call to \tcode{ranges::begin(t)}.
\end{note}
\end{itemize}
\end{itemdescr}

\rSec2[range.prim.empty]{\tcode{ranges::empty}}
\indexlibraryglobal{empty}%

Expand Down Expand Up @@ -1463,6 +1423,46 @@
\end{example}
\end{itemdescr}

\rSec2[range.approximately.sized]{Approximately sized ranges}

\pnum
The \libconcept{approximately_sized_range} concept refines \libconcept{range}
with the requirement that
an approximation of the number of elements in the range
can be determined in amortized constant time using \tcode{ranges::reserve_hint}.

\begin{itemdecl}
template<class T>
concept @\deflibconcept{approximately_sized_range}@ =
@\libconcept{range}@<T> && requires(T& t) { ranges::reserve_hint(t); };
\end{itemdecl}

\begin{itemdescr}
\pnum
Given an lvalue \tcode{t} of type \tcode{remove_reference_t<T>},
\tcode{T} models \libconcept{approximately_sized_range} only if
\begin{itemize}
\item
\tcode{ranges::reserve_hint(t)} is amortized \bigoh{1},
does not modify \tcode{t}, and
has a value that
is not negative and is representable in \tcode{range_difference_t<T>}, and
\item
if \tcode{iterator_t<T>} models \libconcept{forward_iterator},
\tcode{ranges::reserve_hint(t)} is well-defined
regardless of the evaluation of \tcode{ranges::begin(t)}.
\begin{note}
\tcode{ranges::reserve_hint(t)} is otherwise not required to be well-defined
after evaluating \tcode{ranges::\linebreak begin(t)}.
For example,
it is possible for \tcode{ranges::reserve_hint(t)} to be well-defined for
an \libconceptx{approximate\-ly_sized_range}{approximately_sized_range} whose
iterator type does not model \libconcept{forward_iterator}
only if evaluated before the first call to \tcode{ranges::begin(t)}.
\end{note}
\end{itemize}
\end{itemdescr}

\rSec2[range.sized]{Sized ranges}

\pnum
Expand Down