From 57f069a213659f5befaa4a9d88f482a16434716a Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Sat, 24 Jun 2023 22:40:06 +0200 Subject: [PATCH] P2495R3 Interfacing stringstreams with string_view --- source/iostreams.tex | 224 +++++++++++++++++++++++++++++++++++++++++++ source/support.tex | 1 + 2 files changed, 225 insertions(+) diff --git a/source/iostreams.tex b/source/iostreams.tex index bf9dbe8f30..2447cadecc 100644 --- a/source/iostreams.tex +++ b/source/iostreams.tex @@ -7952,6 +7952,13 @@ explicit basic_stringbuf( const basic_string& s, ios_base::openmode which = ios_base::in | ios_base::out); + template + explicit basic_stringbuf(const T& t, + ios_base::openmode which = ios_base::in | ios_base::out); + template + basic_stringbuf(const T& t, const Allocator& a); + template + basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a); basic_stringbuf(const basic_stringbuf&) = delete; basic_stringbuf(basic_stringbuf&& rhs); basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a); @@ -7974,6 +7981,8 @@ template void str(const basic_string& s); void str(basic_string&& s); + template + void str(const T& t); protected: // \ref{stringbuf.virtuals}, overridden virtual functions @@ -8142,6 +8151,37 @@ then calls \tcode{init_buf_ptrs()}. \end{itemdescr} +\indexlibraryctor{basic_stringbuf}% +\begin{itemdecl} +template + explicit basic_stringbuf(const T& t, ios_base::openmode which = ios_base::in | ios_base::out); +template + basic_stringbuf(const T& t, const Allocator& a); +template + basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a); +\end{itemdecl} + +\begin{itemdescr} +\pnum +Let \tcode{which} be \tcode{ios_base::in | ios_base::out} +for the overload with no parameter \tcode{which}, and +\tcode{a} be \tcode{Allocator()} for the overload with no parameter \tcode{a}. + +\pnum +\constraints +\tcode{is_convertible_v>} +is \tcode{true}. + +\pnum +\effects +Creates a variable \tcode{sv} as if by +\tcode{basic_string_view sv = t}, +then value-initializes the base class, +initializes \tcode{mode} with \tcode{which}, and +direct-non-list-initializes \tcode{buf} with \tcode{sv, a}, +then calls \tcode{init_buf_ptrs()}. +\end{itemdescr} + \indexlibraryctor{basic_stringbuf}% \begin{itemdecl} basic_stringbuf(basic_stringbuf&& rhs); @@ -8444,6 +8484,28 @@ \end{codeblock} \end{itemdescr} +\indexlibrarymember{str}{basic_stringbuf}% +\begin{itemdecl} +template + void str(const T& t); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{is_convertible_v>} +is \tcode{true}. + +\pnum +\effects +Equivalent to: +\begin{codeblock} +basic_string_view sv = t; +buf = sv; +init_buf_ptrs(); +\end{codeblock} +\end{itemdescr} + \rSec3[stringbuf.virtuals]{Overridden virtual functions} \indexlibrarymember{underflow}{basic_stringbuf}% @@ -8749,6 +8811,12 @@ explicit basic_istringstream( const basic_string& s, ios_base::openmode which = ios_base::in); + template + explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); + template + basic_istringstream(const T& t, const Allocator& a); + template + basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a); basic_istringstream(const basic_istringstream&) = delete; basic_istringstream(basic_istringstream&& rhs); @@ -8770,6 +8838,8 @@ template void str(const basic_string& s); void str(basic_string&& s); + template + void str(const T& t); private: basic_stringbuf sb; // \expos @@ -8879,6 +8949,10 @@ \end{itemdecl} \begin{itemdescr} +\pnum +\constraints +\tcode{is_same_v} is \tcode{false}. + \pnum \effects Initializes the base class with @@ -8887,6 +8961,33 @@ \tcode{basic_stringbuf(s, which | ios_base::in)}\iref{stringbuf.cons}. \end{itemdescr} +\indexlibraryctor{basic_istringstream}% +\begin{itemdecl} +template + explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); +template + basic_istringstream(const T& t, const Allocator& a); +template + basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a); +\end{itemdecl} + +\begin{itemdescr} +\pnum +Let \tcode{which} be \tcode{ios_base::in} +for the overload with no parameter \tcode{which}, and +\tcode{a} be \tcode{Allocator()} for the overload with no parameter \tcode{a}. + +\pnum +\constraints +\tcode{is_convertible_v>} +is \tcode{true}. + +\pnum +\effects +Initializes the base class with \tcode{addressof(sb)}, and +direct-non-list-initializes \tcode{sb} with \tcode{t, which | ios_base::in, a}. +\end{itemdescr} + \indexlibraryctor{basic_istringstream}% \begin{itemdecl} basic_istringstream(basic_istringstream&& rhs); @@ -9018,12 +9119,30 @@ \begin{itemdecl} void str(basic_string&& s); \end{itemdecl} + \begin{itemdescr} \pnum \effects Equivalent to: \tcode{rdbuf()->str(std::move(s));} \end{itemdescr} +\indexlibrarymember{str}{basic_istringstream}% +\begin{itemdecl} +template + void str(const T& t); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{is_convertible_v>} +is \tcode{true}. + +\pnum +\effects +Equivalent to: \tcode{rdbuf()->str(t);} +\end{itemdescr} + \rSec2[ostringstream]{Class template \tcode{basic_ostringstream}} \rSec3[ostringstream.general]{General} @@ -9064,6 +9183,12 @@ explicit basic_ostringstream( const basic_string& s, ios_base::openmode which = ios_base::out); + template + explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out); + template + basic_ostringstream(const T& t, const Allocator& a); + template + basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a); basic_ostringstream(const basic_ostringstream&) = delete; basic_ostringstream(basic_ostringstream&& rhs); @@ -9086,6 +9211,8 @@ template void str(const basic_string& s); void str(basic_string&& s); + template + void str(const T& t); private: basic_stringbuf sb; // \expos @@ -9207,6 +9334,33 @@ \tcode{basic_stringbuf(s, which | ios_base::out)}\linebreak\iref{stringbuf.cons}. % avoid Overfull \end{itemdescr} +\indexlibraryctor{basic_ostringstream}% +\begin{itemdecl} +template + explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out); +template + basic_ostringstream(const T& t, const Allocator& a); +template + basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a); +\end{itemdecl} + +\begin{itemdescr} +\pnum +Let \tcode{which} be \tcode{ios_base::out} +for the overload with no parameter \tcode{which}, and +\tcode{a} be \tcode{Allocator()} for the overload with no parameter \tcode{a}. + +\pnum +\constraints +\tcode{is_convertible_v>} +is \tcode{true}. + +\pnum +\effects +Initializes the base class with \tcode{addressof(sb)}, and +direct-non-list-initializes \tcode{sb} with \tcode{t, which | ios_base::out, a}. +\end{itemdescr} + \indexlibraryctor{basic_ostringstream}% \begin{itemdecl} basic_ostringstream(basic_ostringstream&& rhs); @@ -9344,6 +9498,23 @@ Equivalent to: \tcode{rdbuf()->str(std::move(s));} \end{itemdescr} +\indexlibrarymember{str}{basic_ostringstream}% +\begin{itemdecl} +template + void str(const T& t); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{is_convertible_v>} +is \tcode{true}. + +\pnum +\effects +Equivalent to: \tcode{rdbuf()->str(t);} +\end{itemdescr} + \rSec2[stringstream]{Class template \tcode{basic_stringstream}} \rSec3[stringstream.general]{General} @@ -9384,6 +9555,13 @@ explicit basic_stringstream( const basic_string& s, ios_base::openmode which = ios_base::out | ios_base::in); + template + explicit basic_stringstream(const T& t, + ios_base::openmode which = ios_base::out | ios_base::in); + template + basic_stringstream(const T& t, const Allocator& a); + template + basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a); basic_stringstream(const basic_stringstream&) = delete; basic_stringstream(basic_stringstream&& rhs); @@ -9406,6 +9584,8 @@ template void str(const basic_string& s); void str(basic_string&& s); + template + void str(const T& t); private: basic_stringbuf sb; // \expos @@ -9532,6 +9712,33 @@ \tcode{basic_stringbuf(s, which)}\iref{stringbuf.cons}. \end{itemdescr} +\indexlibraryctor{basic_stringstream}% +\begin{itemdecl} +template + explicit basic_stringstream(const T& t, ios_base::openmode which = ios_base::out | ios_base::in); +template + basic_stringstream(const T& t, const Allocator& a); +template + basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a); +\end{itemdecl} + +\begin{itemdescr} +\pnum +Let \tcode{which} be \tcode{ios_base::out | ios_base::in} +for the overload with no parameter \tcode{which}, and +\tcode{a} be \tcode{Allocator()} for the overload with no parameter \tcode{a}. + +\pnum +\constraints +\tcode{is_convertible_v>} +is \tcode{true}. + +\pnum +\effects +Initializes the base class with \tcode{addressof(sb)}, and +direct-non-list-initializes \tcode{sb} with \tcode{t, which, a}. +\end{itemdescr} + \indexlibraryctor{basic_stringstream}% \begin{itemdecl} basic_stringstream(basic_stringstream&& rhs); @@ -9669,6 +9876,23 @@ Equivalent to: \tcode{rdbuf()->str(std::move(s));} \end{itemdescr} +\indexlibrarymember{str}{basic_stringstream}% +\begin{itemdecl} +template + void str(const T&); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{is_convertible_v>} +is \tcode{true}. + +\pnum +\effects +Equivalent to: \tcode{rdbuf()->str(t);} +\end{itemdescr} + \rSec1[span.streams]{Span-based streams} \rSec2[span.streams.overview]{Overview} diff --git a/source/support.tex b/source/support.tex index d32d15f9b6..455ae22e5c 100644 --- a/source/support.tex +++ b/source/support.tex @@ -725,6 +725,7 @@ #define @\defnlibxname{cpp_lib_span}@ 202002L // also in \libheader{span} #define @\defnlibxname{cpp_lib_spanstream}@ 202106L // also in \libheader{spanstream} #define @\defnlibxname{cpp_lib_ssize}@ 201902L // also in \libheader{iterator} +#define @\defnlibxname{cpp_lib_sstream_from_string_view}@ 202306L // also in \libheader{sstream} #define @\defnlibxname{cpp_lib_stacktrace}@ 202011L // also in \libheader{stacktrace} #define @\defnlibxname{cpp_lib_start_lifetime_as}@ 202207L // also in \libheader{memory} #define @\defnlibxname{cpp_lib_starts_ends_with}@ 201711L // also in \libheader{string}, \libheader{string_view}