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

[LWG 12] P2870R3 Remove deprecated basic_string::reserve() with no parameters #6709

Merged
merged 2 commits into from
Dec 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 33 additions & 21 deletions source/compatibility.tex
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@
// changed according to the global C locale
\end{codeblock}

\rSec2[diff.cpp23.containers]{\ref{containers}: containers library}

\diffref{span.overview}
\change
\tcode{span<const T>} is constructible from \tcode{initializer_list<T>}.
\rationale
Permit passing a braced initializer list to a function taking \tcode{span}.
\effect
Valid \CppXXIII{} code that relies on the lack of this constructor
may refuse to compile, or change behavior in this revision of \Cpp{}.
For example:
\begin{codeblock}
void one(pair<int, int>); // \#1
void one(span<const int>); // \#2
void t1() { one({1, 2}); } // ambiguous between \#1 and \#2; previously called \#1

void two(span<const int, 2>);
void t2() { two({{1, 2}}); } // ill-formed; previously well-formed

void *a[10];
int x = span<void* const>{a, 0}.size(); // \tcode{x} is \tcode{2}; previously \tcode{0}
any b[10];
int y = span<const any>{b, b + 10}.size(); // \tcode{y} is \tcode{2}; previously \tcode{10}
\end{codeblock}

\rSec2[diff.cpp23.depr]{\ref{depr}: compatibility features}

\nodiffref
Expand All @@ -129,30 +154,17 @@
// OK in \CppXXVI{}
\end{codeblock}

\rSec2[diff.cpp23.containers]{\ref{containers}: containers library}

\diffref{span.overview}
\nodiffref
\change
\tcode{span<const T>} is constructible from \tcode{initializer_list<T>}.
Remove the \tcode{basic_string::reserve()} overload with no parameters.
\rationale
Permit passing a braced initializer list to a function taking \tcode{span}.
The overload of \tcode{reserve} with no parameters is redundant.
The \tcode{shrink_to_fit} member function can be used instead.
\effect
Valid \CppXXIII{} code that relies on the lack of this constructor
may refuse to compile, or change behavior in this revision of \Cpp{}.
For example:
\begin{codeblock}
void one(pair<int, int>); // \#1
void one(span<const int>); // \#2
void t1() { one({1, 2}); } // ambiguous between \#1 and \#2; previously called \#1

void two(span<const int, 2>);
void t2() { two({{1, 2}}); } // ill-formed; previously well-formed

void *a[10];
int x = span<void* const>{a, 0}.size(); // \tcode{x} is \tcode{2}; previously \tcode{0}
any b[10];
int y = span<const any>{b, b + 10}.size(); // \tcode{y} is \tcode{2}; previously \tcode{10}
\end{codeblock}
A valid \CppXXIII{} program that calls \tcode{reserve()}
on a \tcode{basic_string} object may fail to compile.
The old functionality can be achieved by calling \tcode{shrink_to_fit()} instead,
or the function call can be safely eliminated with no side effects.

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

Expand Down
33 changes: 0 additions & 33 deletions source/future.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1995,39 +1995,6 @@
The weak form may fail spuriously. See~\ref{atomics.types.operations}.
\end{itemdescr}

\rSec1[depr.string.capacity]{Deprecated \tcode{basic_string} capacity}

\pnum
The following member is declared in addition to those members specified
in \ref{string.capacity}:

\indexlibraryglobal{basic_string}%
\begin{codeblock}
namespace std {
template<class charT, class traits = char_traits<charT>,
class Allocator = allocator<charT>>
class basic_string {
public:
void reserve();
};
}
\end{codeblock}

\indexlibrarymember{reserve}{basic_string}%
\begin{itemdecl}
void reserve();
\end{itemdecl}

\begin{itemdescr}
\pnum
\effects
After this call, \tcode{capacity()} has an unspecified value
greater than or equal to \tcode{size()}.
\begin{note}
This is a non-binding shrink to fit request.
\end{note}
\end{itemdescr}

\rSec1[depr.format]{Deprecated formatting}

\rSec2[depr.format.syn]{Header \tcode{<format>} synopsis}
Expand Down
3 changes: 3 additions & 0 deletions source/xrefdelta.tex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
% P2874R2 Mandating Annex D
\removedxref{depr.res.on.required}

% P2870R3 Remove `basic_string::reserve()` with no parameters
\removedxref{depr.string.capacity}

%%% Renamed sections.
%%% Examples:
%
Expand Down