Skip to content

Commit df23ae2

Browse files
burblebeetkoeppe
authored andcommitted
P2846R6 reserve_hint: Eagerly reserving memory for not-quite-sized lazy ranges
The wording has been reconciled with the earlier changes from the resolution of issue LWG 4189, which made most of <ranges> free-standing, noting "Most future additions to this header should have no problem being freestanding, so that is the right default." Consequently, "reserve_hint" and "approximately_sized_range" are now also free-standing.
1 parent 103af7a commit df23ae2

File tree

3 files changed

+578
-23
lines changed

3 files changed

+578
-23
lines changed

source/containers.tex

+47-5
Original file line numberDiff line numberDiff line change
@@ -1403,14 +1403,23 @@
14031403
from \tcode{*ranges::begin(rg)}.
14041404
For \tcode{vector},
14051405
if \tcode{R} models
1406-
neither \tcode{ranges::\libconcept{sized_range}} nor \tcode{ranges::\libconcept{forward_range}},
1406+
\tcode{ranges::\libconcept{approximately_sized_range}}
1407+
but not \tcode{ranges::\libconcept{sized_range}} or models
1408+
\tcode{ranges::\libconcept{input_range}}
1409+
but not \tcode{ranges::\libconcept{forward_range}},
14071410
\tcode{T} is also \oldconcept{MoveInsertable} into \tcode{X}.
14081411

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

1417+
\pnum
1418+
\recommended
1419+
If \tcode{R} models \tcode{ranges::\libconcept{approximately_sized_range}} and
1420+
\tcode{ranges::distance(\linebreak{}rg) <= ranges::reserve_hint(rg)} is \tcode{true},
1421+
an implementation should not perform any reallocation.
1422+
14141423
\pnum
14151424
\ensures
14161425
\tcode{distance(begin(), end()) == ranges::distance(rg)} is \tcode{true}.
@@ -1761,7 +1770,10 @@
17611770
from \tcode{*ranges::begin(rg)}.
17621771
For \tcode{vector},
17631772
if \tcode{R} models
1764-
neither \tcode{ranges::\libconcept{sized_range}} nor \tcode{ranges::\libconcept{forward_range}},
1773+
\tcode{ranges::\libconcept{approximately_sized_range}}
1774+
but not \tcode{ranges::\libconcept{sized_range}} or models
1775+
\tcode{ranges::\libconcept{input_range}}
1776+
but not \tcode{ranges::\libconcept{forward_range}},
17651777
\tcode{T} is also \oldconcept{MoveInsertable} into \tcode{X}.
17661778
\tcode{rg} and \tcode{a} do not overlap.
17671779

@@ -1773,6 +1785,12 @@
17731785
For \tcode{vector} and \tcode{deque},
17741786
also invalidates the past-the-end iterator.
17751787
Each iterator in the range \tcode{rg} is dereferenced exactly once.
1788+
1789+
\pnum
1790+
\recommended
1791+
If \tcode{R} models \tcode{ranges::\libconcept{approximately_sized_range}} and
1792+
\tcode{ranges::distance(\linebreak{}rg) <= ranges::reserve_hint(rg)} is \tcode{true},
1793+
an implementation should not perform any reallocation.
17761794
\end{itemdescr}
17771795

17781796
\begin{itemdecl}
@@ -8929,9 +8947,18 @@
89298947
Initializes exactly $N$ elements
89308948
from the results of dereferencing successive iterators of \tcode{rg},
89318949
where $N$ is \tcode{ranges::distance(rg)}.
8932-
Performs no reallocations if \tcode{R} models
8933-
\tcode{ranges::\libconcept{forward_range}} or \tcode{ranges::\libconcept{sized_range}};
8934-
otherwise, performs order $\log N$ reallocations and
8950+
8951+
\pnum
8952+
Performs no reallocations if:
8953+
\begin{itemize}
8954+
\item
8955+
\tcode{R} models \tcode{ranges::\libconcept{approximately_sized_range}}, and
8956+
\tcode{ranges::distance(rg) <= ranges::re\-serve_hint(rg)} is \tcode{true}, or
8957+
\item
8958+
\tcode{R} models \tcode{ranges::\libconcept{forward_range}} and
8959+
\tcode{R} does not model \tcode{ranges::approximately_sized_range}.
8960+
\end{itemize}
8961+
Otherwise, performs order $\log N$ reallocations and
89358962
order $N$ calls to the copy or move constructor of \tcode{T}.
89368963
\end{itemdescr}
89378964

@@ -9182,6 +9209,21 @@
91829209
is \tcode{true}, there are no effects.
91839210
Otherwise, if an exception is thrown by the move constructor of a non-\oldconcept{CopyInsertable}
91849211
\tcode{T}, the effects are unspecified.
9212+
9213+
\pnum
9214+
For the declarations taking a range \tcode{R},
9215+
performs at most one reallocation if:
9216+
\begin{itemize}
9217+
\item
9218+
\tcode{R} models \tcode{ranges::\libconcept{approximately_sized_range}} and
9219+
\tcode{ranges::distance(rg) <= ranges::re\-serve_hint(rg)} is \tcode{true}, or
9220+
\item
9221+
\tcode{R} models \tcode{ranges::\libconcept{forward_range}} and
9222+
\tcode{R} does not model \tcode{ranges::\libconcept{approximately_sized_range}}.
9223+
\end{itemize}
9224+
For the declarations taking a pair of \tcode{InputIterator},
9225+
performs at most one reallocation if
9226+
\tcode{InputItera\-tor} models \oldconcept{ForwardIterator}.
91859227
\end{itemdescr}
91869228

91879229
\indexlibrarymember{erase}{vector}%

0 commit comments

Comments
 (0)