Skip to content

Commit af2460a

Browse files
authored
Merge 2021-10 LWG Motion 9
P1072R10 basic_string::resize_and_overwrite
2 parents b9b0477 + e2740a0 commit af2460a

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

source/containers.tex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
\end{example}
5555

5656
\pnum
57-
For the components affected by this subclause that declare an \tcode{allocator_type},
58-
objects stored in these components shall be constructed using the function
57+
Allocator-aware containers (\tref{container.alloc.req})
58+
other than \tcode{basic_string} construct elements using the function
5959
\tcode{allocator_traits<allocator_type>::rebind_traits<U>::\brk{}construct}
60-
and destroyed using the function
60+
and destroy elements using the function
6161
\tcode{allocator_traits<allocator_type>::rebind_traits<U>::\brk{}destroy}\iref{allocator.traits.members},
6262
where \tcode{U} is either \tcode{allocator_type::value_type} or
6363
an internal type used by the container.
@@ -541,7 +541,8 @@
541541
an expression \tcode{v} of type (possibly \keyword{const}) \tcode{T},
542542
and an rvalue \tcode{rv} of type \tcode{T},
543543
the following terms are defined. If \tcode{X}
544-
is not allocator-aware, the terms below are defined as if \tcode{A} were
544+
is not allocator-aware or is a specialization of \tcode{basic_string},
545+
the terms below are defined as if \tcode{A} were
545546
\tcode{allocator<T>} --- no allocator object needs to be created
546547
and user specializations of \tcode{allocator<T>} are not instantiated:
547548

source/strings.tex

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@
868868
constexpr size_type max_size() const noexcept;
869869
constexpr void resize(size_type n, charT c);
870870
constexpr void resize(size_type n);
871+
template<class Operation> constexpr void resize_and_overwrite(size_type n, Operation op);
871872
constexpr size_type capacity() const noexcept;
872873
constexpr void reserve(size_type res_arg);
873874
constexpr void shrink_to_fit();
@@ -1109,6 +1110,12 @@
11091110
the type \tcode{traits} shall meet
11101111
the character traits requirements\iref{char.traits}.
11111112
\begin{note}
1113+
Every specialization \tcode{basic_string<charT, traits, Allocator>} is
1114+
an allocator-aware container,
1115+
but does not use the allocator's \tcode{construct} and \tcode{destroy}
1116+
member functions\iref{container.requirements.general}.
1117+
\end{note}
1118+
\begin{note}
11121119
The program is ill-formed if \tcode{traits::char_type}
11131120
is not the same type as \tcode{charT}.
11141121
\end{note}
@@ -1609,6 +1616,61 @@
16091616
Equivalent to \tcode{resize(n, charT())}.
16101617
\end{itemdescr}
16111618

1619+
\indexlibrarymember{resize_and_overwrite}{basic_string}%
1620+
\begin{itemdecl}
1621+
template<class Operation> constexpr void resize_and_overwrite(size_type n, Operation op);
1622+
\end{itemdecl}
1623+
1624+
\begin{itemdescr}
1625+
\pnum
1626+
Let
1627+
\begin{itemize}
1628+
\item
1629+
\tcode{o = size()} before the call to \tcode{resize_and_overwrite}.
1630+
\item
1631+
\tcode{k} be \tcode{min(o, n)}.
1632+
\item
1633+
\tcode{p} be a \tcode{charT*},
1634+
such that the range \crange{p}{p + n} is valid and
1635+
\tcode{this->compare(0, k, p, k) == 0} is \tcode{true} before the call.
1636+
The values in the range \crange{p + k}{p + n} may be indeterminate\iref{basic.indet}.
1637+
\item
1638+
$OP$ be the expression \tcode{std::move(op)(p, n)}.
1639+
\item
1640+
\tcode{r} = $OP$.
1641+
\end{itemize}
1642+
1643+
\pnum
1644+
\mandates
1645+
$OP$ has an integer-like type\iref{iterator.concept.winc}.
1646+
1647+
\pnum
1648+
\expects
1649+
\begin{itemize}
1650+
\item
1651+
$OP$ does not throw an exception or modify \tcode{p} or \tcode{n}.
1652+
\item
1653+
$\tcode{r} \geq 0$.
1654+
\item
1655+
$\tcode{r} \leq \tcode{n}$.
1656+
\item
1657+
After evaluating $OP$
1658+
there are no indeterminate values in the range \range{p}{p + r}.
1659+
\end{itemize}
1660+
1661+
\pnum
1662+
\effects
1663+
Evaluates $OP$,
1664+
replaces the contents of \tcode{*this} with \range{p}{p + r}, and
1665+
invalidates all pointers and references to the range \crange{p}{p + n}.
1666+
1667+
\pnum
1668+
\recommended
1669+
Implementations should avoid unnecessary copies and allocations
1670+
by, for example, making \tcode{p} a pointer into internal storage and
1671+
by restoring \tcode{*(p + r)} to \tcode{charT()} after evaluating $OP$.
1672+
\end{itemdescr}
1673+
16121674
\indexlibrarymember{capacity}{basic_string}%
16131675
\begin{itemdecl}
16141676
constexpr size_type capacity() const noexcept;

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@
686686
#define @\defnlibxname{cpp_lib_starts_ends_with}@ 201711L // also in \libheader{string}, \libheader{string_view}
687687
#define @\defnlibxname{cpp_lib_stdatomic_h}@ 202011L // also in \libheader{stdatomic.h}
688688
#define @\defnlibxname{cpp_lib_string_contains}@ 202011L // also in \libheader{string}, \libheader{string_view}
689+
#define @\defnlibxname{cpp_lib_string_resize_and_overwrite}@ 202110L // also in \libheader{string}
689690
#define @\defnlibxname{cpp_lib_string_udls}@ 201304L // also in \libheader{string}
690691
#define @\defnlibxname{cpp_lib_string_view}@ 201803L // also in \libheader{string}, \libheader{string_view}
691692
#define @\defnlibxname{cpp_lib_syncbuf}@ 201803L // also in \libheader{syncstream}

0 commit comments

Comments
 (0)