Skip to content

Commit 8ea5a81

Browse files
authored
Merge 2023-11 LWG Motion 12
P2870R3 Remove deprecated basic_string::reserve() with no parameters
2 parents 58c6c79 + 568e49f commit 8ea5a81

File tree

3 files changed

+36
-54
lines changed

3 files changed

+36
-54
lines changed

source/compatibility.tex

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@
107107
// changed according to the global C locale
108108
\end{codeblock}
109109

110+
\rSec2[diff.cpp23.containers]{\ref{containers}: containers library}
111+
112+
\diffref{span.overview}
113+
\change
114+
\tcode{span<const T>} is constructible from \tcode{initializer_list<T>}.
115+
\rationale
116+
Permit passing a braced initializer list to a function taking \tcode{span}.
117+
\effect
118+
Valid \CppXXIII{} code that relies on the lack of this constructor
119+
may refuse to compile, or change behavior in this revision of \Cpp{}.
120+
For example:
121+
\begin{codeblock}
122+
void one(pair<int, int>); // \#1
123+
void one(span<const int>); // \#2
124+
void t1() { one({1, 2}); } // ambiguous between \#1 and \#2; previously called \#1
125+
126+
void two(span<const int, 2>);
127+
void t2() { two({{1, 2}}); } // ill-formed; previously well-formed
128+
129+
void *a[10];
130+
int x = span<void* const>{a, 0}.size(); // \tcode{x} is \tcode{2}; previously \tcode{0}
131+
any b[10];
132+
int y = span<const any>{b, b + 10}.size(); // \tcode{y} is \tcode{2}; previously \tcode{10}
133+
\end{codeblock}
134+
110135
\rSec2[diff.cpp23.depr]{\ref{depr}: compatibility features}
111136

112137
\nodiffref
@@ -129,30 +154,17 @@
129154
// OK in \CppXXVI{}
130155
\end{codeblock}
131156

132-
\rSec2[diff.cpp23.containers]{\ref{containers}: containers library}
133-
134-
\diffref{span.overview}
157+
\nodiffref
135158
\change
136-
\tcode{span<const T>} is constructible from \tcode{initializer_list<T>}.
159+
Remove the \tcode{basic_string::reserve()} overload with no parameters.
137160
\rationale
138-
Permit passing a braced initializer list to a function taking \tcode{span}.
161+
The overload of \tcode{reserve} with no parameters is redundant.
162+
The \tcode{shrink_to_fit} member function can be used instead.
139163
\effect
140-
Valid \CppXXIII{} code that relies on the lack of this constructor
141-
may refuse to compile, or change behavior in this revision of \Cpp{}.
142-
For example:
143-
\begin{codeblock}
144-
void one(pair<int, int>); // \#1
145-
void one(span<const int>); // \#2
146-
void t1() { one({1, 2}); } // ambiguous between \#1 and \#2; previously called \#1
147-
148-
void two(span<const int, 2>);
149-
void t2() { two({{1, 2}}); } // ill-formed; previously well-formed
150-
151-
void *a[10];
152-
int x = span<void* const>{a, 0}.size(); // \tcode{x} is \tcode{2}; previously \tcode{0}
153-
any b[10];
154-
int y = span<const any>{b, b + 10}.size(); // \tcode{y} is \tcode{2}; previously \tcode{10}
155-
\end{codeblock}
164+
A valid \CppXXIII{} program that calls \tcode{reserve()}
165+
on a \tcode{basic_string} object may fail to compile.
166+
The old functionality can be achieved by calling \tcode{shrink_to_fit()} instead,
167+
or the function call can be safely eliminated with no side effects.
156168

157169
\rSec1[diff.cpp20]{\Cpp{} and ISO \CppXX{}}
158170

source/future.tex

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,39 +1995,6 @@
19951995
The weak form may fail spuriously. See~\ref{atomics.types.operations}.
19961996
\end{itemdescr}
19971997

1998-
\rSec1[depr.string.capacity]{Deprecated \tcode{basic_string} capacity}
1999-
2000-
\pnum
2001-
The following member is declared in addition to those members specified
2002-
in \ref{string.capacity}:
2003-
2004-
\indexlibraryglobal{basic_string}%
2005-
\begin{codeblock}
2006-
namespace std {
2007-
template<class charT, class traits = char_traits<charT>,
2008-
class Allocator = allocator<charT>>
2009-
class basic_string {
2010-
public:
2011-
void reserve();
2012-
};
2013-
}
2014-
\end{codeblock}
2015-
2016-
\indexlibrarymember{reserve}{basic_string}%
2017-
\begin{itemdecl}
2018-
void reserve();
2019-
\end{itemdecl}
2020-
2021-
\begin{itemdescr}
2022-
\pnum
2023-
\effects
2024-
After this call, \tcode{capacity()} has an unspecified value
2025-
greater than or equal to \tcode{size()}.
2026-
\begin{note}
2027-
This is a non-binding shrink to fit request.
2028-
\end{note}
2029-
\end{itemdescr}
2030-
20311998
\rSec1[depr.format]{Deprecated formatting}
20321999

20332000
\rSec2[depr.format.syn]{Header \tcode{<format>} synopsis}

source/xrefdelta.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
% P2874R2 Mandating Annex D
2929
\removedxref{depr.res.on.required}
3030

31+
% P2870R3 Remove `basic_string::reserve()` with no parameters
32+
\removedxref{depr.string.capacity}
33+
3134
%%% Renamed sections.
3235
%%% Examples:
3336
%

0 commit comments

Comments
 (0)