Skip to content
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

[2025-02 LWG 14] P2846R6 reserve_hint: Eagerly reserving memory for not-quite-sized lazy ranges #7698

Merged
merged 2 commits into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
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
52 changes: 47 additions & 5 deletions source/containers.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1403,14 +1403,23 @@
from \tcode{*ranges::begin(rg)}.
For \tcode{vector},
if \tcode{R} models
neither \tcode{ranges::\libconcept{sized_range}} nor \tcode{ranges::\libconcept{forward_range}},
\tcode{ranges::\libconcept{approximately_sized_range}}
but not \tcode{ranges::\libconcept{sized_range}} or models
\tcode{ranges::\libconcept{input_range}}
but not \tcode{ranges::\libconcept{forward_range}},
\tcode{T} is also \oldconcept{MoveInsertable} into \tcode{X}.

\pnum
\effects
Constructs a sequence container equal to the range \tcode{rg}.
Each iterator in the range \tcode{rg} is dereferenced exactly once.

\pnum
\recommended
If \tcode{R} models \tcode{ranges::\libconcept{approximately_sized_range}} and
\tcode{ranges::distance(\linebreak{}rg) <= ranges::reserve_hint(rg)} is \tcode{true},
an implementation should not perform any reallocation.

\pnum
\ensures
\tcode{distance(begin(), end()) == ranges::distance(rg)} is \tcode{true}.
Expand Down Expand Up @@ -1761,7 +1770,10 @@
from \tcode{*ranges::begin(rg)}.
For \tcode{vector},
if \tcode{R} models
neither \tcode{ranges::\libconcept{sized_range}} nor \tcode{ranges::\libconcept{forward_range}},
\tcode{ranges::\libconcept{approximately_sized_range}}
but not \tcode{ranges::\libconcept{sized_range}} or models
\tcode{ranges::\libconcept{input_range}}
but not \tcode{ranges::\libconcept{forward_range}},
\tcode{T} is also \oldconcept{MoveInsertable} into \tcode{X}.
\tcode{rg} and \tcode{a} do not overlap.

Expand All @@ -1773,6 +1785,12 @@
For \tcode{vector} and \tcode{deque},
also invalidates the past-the-end iterator.
Each iterator in the range \tcode{rg} is dereferenced exactly once.

\pnum
\recommended
If \tcode{R} models \tcode{ranges::\libconcept{approximately_sized_range}} and
\tcode{ranges::distance(\linebreak{}rg) <= ranges::reserve_hint(rg)} is \tcode{true},
an implementation should not perform any reallocation.
\end{itemdescr}

\begin{itemdecl}
Expand Down Expand Up @@ -8929,9 +8947,18 @@
Initializes exactly $N$ elements
from the results of dereferencing successive iterators of \tcode{rg},
where $N$ is \tcode{ranges::distance(rg)}.
Performs no reallocations if \tcode{R} models
\tcode{ranges::\libconcept{forward_range}} or \tcode{ranges::\libconcept{sized_range}};
otherwise, performs order $\log N$ reallocations and

\pnum
Performs no reallocations if:
\begin{itemize}
\item
\tcode{R} models \tcode{ranges::\libconcept{approximately_sized_range}}, and
\tcode{ranges::distance(rg) <= ranges::re\-serve_hint(rg)} is \tcode{true}, or
\item
\tcode{R} models \tcode{ranges::\libconcept{forward_range}} and
\tcode{R} does not model \tcode{ranges::approximately_sized_range}.
\end{itemize}
Otherwise, performs order $\log N$ reallocations and
order $N$ calls to the copy or move constructor of \tcode{T}.
\end{itemdescr}

Expand Down Expand Up @@ -9182,6 +9209,21 @@
is \tcode{true}, there are no effects.
Otherwise, if an exception is thrown by the move constructor of a non-\oldconcept{CopyInsertable}
\tcode{T}, the effects are unspecified.

\pnum
For the declarations taking a range \tcode{R},
performs at most one reallocation if:
\begin{itemize}
\item
\tcode{R} models \tcode{ranges::\libconcept{approximately_sized_range}} and
\tcode{ranges::distance(rg) <= ranges::re\-serve_hint(rg)} is \tcode{true}, or
\item
\tcode{R} models \tcode{ranges::\libconcept{forward_range}} and
\tcode{R} does not model \tcode{ranges::\libconcept{approximately_sized_range}}.
\end{itemize}
For the declarations taking a pair of \tcode{InputIterator},
performs at most one reallocation if
\tcode{InputItera\-tor} models \oldconcept{ForwardIterator}.
\end{itemdescr}

\indexlibrarymember{erase}{vector}%
Expand Down
Loading