Skip to content

Commit 8a9de02

Browse files
authored
Merge 2022-07 LWG Motion 11
P2093R14 Formatted output
2 parents 37280e0 + 72a78d9 commit 8a9de02

File tree

4 files changed

+289
-0
lines changed

4 files changed

+289
-0
lines changed

source/back.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ \chapter{Bibliography}
3131
Edited by Mark Davis. Revision 33; issued for Unicode 13.0.0.
3232
2020-02-13 [viewed 2021-06-08].
3333
Available from: \url{https://www.unicode.org/reports/tr31/tr31-33.html}
34+
\item
35+
The Unicode Standard Version 14.0,
36+
\doccite{Core Specification}.
37+
Unicode Consortium, ISBN 978-1-936213-29-0, copyright \copyright 2021 Unicode, Inc.
38+
Available from: \url{https://www.unicode.org/versions/Unicode14.0.0/UnicodeStandard-14.0.pdf}
3439
\item
3540
IANA Time Zone Database.
3641
Available from: \url{https://www.iana.org/time-zones}

source/iostreams.tex

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4162,6 +4162,15 @@
41624162

41634163
template<class Ostream, class T>
41644164
Ostream&& operator<<(Ostream&& os, const T& x);
4165+
4166+
// \ref{ostream.formatted.print}, print functions
4167+
template<class... Args>
4168+
void print(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args);
4169+
template<class... Args>
4170+
void println(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args);
4171+
4172+
void vprint_unicode(ostream& os, string_view fmt, format_args args);
4173+
void vprint_nonunicode(ostream& os, string_view fmt, format_args args);
41654174
}
41664175
\end{codeblock}
41674176

@@ -4203,6 +4212,30 @@
42034212
}
42044213
\end{codeblock}
42054214

4215+
\rSec2[print.syn]{Header \tcode{<print>} synopsis}
4216+
4217+
\indexheader{print}%
4218+
\begin{codeblock}
4219+
namespace std {
4220+
// \ref{print.fun}, print functions
4221+
template<class... Args>
4222+
void print(@\exposid{format-string}@<Args...> fmt, Args&&... args);
4223+
template<class... Args>
4224+
void print(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args);
4225+
4226+
template<class... Args>
4227+
void println(@\exposid{format-string}@<Args...> fmt, Args&&... args);
4228+
template<class... Args>
4229+
void println(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args);
4230+
4231+
void vprint_unicode(string_view fmt, format_args args);
4232+
void vprint_unicode(FILE* stream, string_view fmt, format_args args);
4233+
4234+
void vprint_nonunicode(string_view fmt, format_args args);
4235+
void vprint_nonunicode(FILE* stream, string_view fmt, format_args args);
4236+
}
4237+
\end{codeblock}
4238+
42064239
\rSec2[input.streams]{Input streams}
42074240

42084241
\rSec3[input.streams.general]{General}
@@ -6767,6 +6800,92 @@
67676800
\tcode{out}.
67686801
\end{itemdescr}
67696802

6803+
\rSec4[ostream.formatted.print]{Print}
6804+
6805+
\indexlibraryglobal{print}%
6806+
\begin{itemdecl}
6807+
template<class... Args>
6808+
void print(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args);
6809+
\end{itemdecl}
6810+
6811+
\begin{itemdescr}
6812+
\pnum
6813+
\effects
6814+
If the ordinary literal encoding\iref{lex.charset} is UTF-8, equivalent to:
6815+
\begin{codeblock}
6816+
vprint_unicode(os, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...));
6817+
\end{codeblock}
6818+
Otherwise, equivalent to:
6819+
\begin{codeblock}
6820+
vprint_nonunicode(os, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...));
6821+
\end{codeblock}
6822+
\end{itemdescr}
6823+
6824+
\indexlibraryglobal{println}%
6825+
\begin{itemdecl}
6826+
template<class... Args>
6827+
void println(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args);
6828+
\end{itemdecl}
6829+
6830+
\begin{itemdescr}
6831+
\pnum
6832+
\effects
6833+
Equivalent to:
6834+
\begin{codeblock}
6835+
print(os, "{}\n", format(fmt, std::forward<Args>(args)...));
6836+
\end{codeblock}
6837+
\end{itemdescr}
6838+
6839+
\indexlibraryglobal{vprint_unicode}%
6840+
\indexlibraryglobal{vprint_nonunicode}%
6841+
\begin{itemdecl}
6842+
void vprint_unicode(ostream& os, string_view fmt, format_args args);
6843+
void vprint_nonunicode(ostream& os, string_view fmt, format_args args);
6844+
\end{itemdecl}
6845+
6846+
\begin{itemdescr}
6847+
\pnum
6848+
\effects
6849+
Behaves as a formatted output function\iref{ostream.formatted.reqmts}
6850+
of \tcode{os}, except that:
6851+
\begin{itemize}
6852+
\item
6853+
failure to generate output is reported as specified below, and
6854+
\item
6855+
any exception thrown by the call to \tcode{vformat} is propagated
6856+
without regard to the value of \tcode{os.exceptions()} and
6857+
without turning on \tcode{ios_base::badbit} in the error state of \tcode{os}.
6858+
\end{itemize}
6859+
After constructing a \tcode{sentry} object,
6860+
the function initializes an automatic variable via
6861+
\begin{codeblock}
6862+
string out = vformat(os.getloc(), fmt, args);
6863+
\end{codeblock}
6864+
If the function is \tcode{vprint_unicode} and
6865+
\tcode{os} is a stream that refers to a terminal capable of displaying Unicode
6866+
which is determined in an implementation-defined manner,
6867+
writes \tcode{out} to the terminal using the native Unicode API;
6868+
if \tcode{out} contains invalid code units,
6869+
\indextext{undefined}%
6870+
the behavior is undefined and
6871+
implementations are encouraged to diagnose it.
6872+
Otherwise (if \tcode{os} is not such a stream or
6873+
the function is \tcode{vprint_nonunicode}),
6874+
inserts the character sequence
6875+
\range{out.begin()}{out.end()} into \tcode{os}.
6876+
If writing to the terminal or inserting into \tcode{os} fails,
6877+
calls \tcode{os.setstate(ios_base::badbit)}
6878+
(which may throw \tcode{ios_base::failure}).
6879+
6880+
\pnum
6881+
\recommended
6882+
For \tcode{vprint_unicode},
6883+
if invoking the native Unicode API requires transcoding,
6884+
implementations should substitute invalid code units
6885+
with \unicode{fffd}{replacement character} per
6886+
The Unicode Standard Version 14.0 - Core Specification, Chapter 3.9.
6887+
\end{itemdescr}
6888+
67706889
\rSec3[ostream.unformatted]{Unformatted output functions}
67716890

67726891
\pnum
@@ -7573,6 +7692,169 @@
75737692
\end{itemize}
75747693
\end{itemdescr}
75757694

7695+
\rSec2[print.fun]{Print functions}
7696+
7697+
\indexlibraryglobal{print}%
7698+
\begin{itemdecl}
7699+
template<class... Args>
7700+
void print(@\exposid{format-string}@<Args...> fmt, Args&&... args);
7701+
\end{itemdecl}
7702+
7703+
\begin{itemdescr}
7704+
\pnum
7705+
\effects
7706+
Equivalent to:
7707+
\begin{codeblock}
7708+
print(stdout, fmt, std::forward<Args>(args)...);
7709+
\end{codeblock}
7710+
\end{itemdescr}
7711+
7712+
\indexlibraryglobal{print}%
7713+
\begin{itemdecl}
7714+
template<class... Args>
7715+
void print(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args);
7716+
\end{itemdecl}
7717+
7718+
\begin{itemdescr}
7719+
\pnum
7720+
\effects
7721+
If the ordinary literal encoding\iref{lex.charset} is UTF-8, equivalent to:
7722+
\begin{codeblock}
7723+
vprint_unicode(stream, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...));
7724+
\end{codeblock}
7725+
Otherwise, equivalent to:
7726+
\begin{codeblock}
7727+
vprint_nonunicode(stream, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...));
7728+
\end{codeblock}
7729+
\end{itemdescr}
7730+
7731+
\indexlibraryglobal{println}%
7732+
\begin{itemdecl}
7733+
template<class... Args>
7734+
void println(@\exposid{format-string}@<Args...> fmt, Args&&... args);
7735+
\end{itemdecl}
7736+
7737+
\begin{itemdescr}
7738+
\pnum
7739+
\effects
7740+
Equivalent to:
7741+
\begin{codeblock}
7742+
println(stdout, fmt, std::forward<Args>(args)...);
7743+
\end{codeblock}
7744+
\end{itemdescr}
7745+
7746+
\indexlibraryglobal{println}%
7747+
\begin{itemdecl}
7748+
template<class... Args>
7749+
void println(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args);
7750+
\end{itemdecl}
7751+
7752+
\begin{itemdescr}
7753+
\pnum
7754+
\effects
7755+
Equivalent to:
7756+
\begin{codeblock}
7757+
print(stream, "{}\n", format(fmt, std::forward<Args>(args)...));
7758+
\end{codeblock}
7759+
\end{itemdescr}
7760+
7761+
\indexlibraryglobal{vprint_unicode}%
7762+
\begin{itemdecl}
7763+
void vprint_unicode(string_view fmt, format_args args);
7764+
\end{itemdecl}
7765+
7766+
\begin{itemdescr}
7767+
\pnum
7768+
\effects
7769+
Equivalent to:
7770+
\begin{codeblock}
7771+
vprint_unicode(stdout, fmt, args);
7772+
\end{codeblock}
7773+
\end{itemdescr}
7774+
7775+
\indexlibraryglobal{vprint_unicode}%
7776+
\begin{itemdecl}
7777+
void vprint_unicode(FILE* stream, string_view fmt, format_args args);
7778+
\end{itemdecl}
7779+
7780+
\begin{itemdescr}
7781+
\pnum
7782+
\expects
7783+
\tcode{stream} is a valid pointer to an output C stream.
7784+
7785+
\pnum
7786+
\effects
7787+
The function initializes an automatic variable via
7788+
\begin{codeblock}
7789+
string out = vformat(fmt, args);
7790+
\end{codeblock}
7791+
If \tcode{stream} refers to a terminal capable of displaying Unicode,
7792+
writes \tcode{out} to the terminal using the native Unicode API;
7793+
if \tcode{out} contains invalid code units,
7794+
\indextext{undefined}%
7795+
the behavior is undefined and
7796+
implementations are encouraged to diagnose it.
7797+
Otherwise writes \tcode{out} to \tcode{stream} unchanged.
7798+
\begin{note}
7799+
On POSIX and Windows, \tcode{stream} referring to a terminal means that,
7800+
respectively,
7801+
\tcode{isatty(fileno(\linebreak{}stream))} and
7802+
\tcode{GetConsoleMode(_get_osfhandle(_fileno(stream)), ...)}
7803+
return nonzero.
7804+
\end{note}
7805+
\begin{note}
7806+
On Windows, the native Unicode API is \tcode{WriteConsoleW}.
7807+
\end{note}
7808+
7809+
\pnum
7810+
\throws
7811+
Any exception thrown by the call to \tcode{vformat}\iref{format.err.report}.
7812+
\tcode{system_error} if writing to the terminal or \tcode{stream} fails.
7813+
May throw \tcode{bad_alloc}.
7814+
7815+
\pnum
7816+
\recommended
7817+
If invoking the native Unicode API requires transcoding,
7818+
implementations should substitute invalid code units
7819+
with \unicode{fffd}{replacement character} per
7820+
The Unicode Standard Version 14.0 - Core Specification, Chapter 3.9.
7821+
\end{itemdescr}
7822+
7823+
\indexlibraryglobal{vprint_nonunicode}%
7824+
\begin{itemdecl}
7825+
void vprint_nonunicode(string_view fmt, format_args args);
7826+
\end{itemdecl}
7827+
7828+
\begin{itemdescr}
7829+
\pnum
7830+
\effects
7831+
Equivalent to:
7832+
\begin{codeblock}
7833+
vprint_nonunicode(stdout, fmt, args);
7834+
\end{codeblock}
7835+
\end{itemdescr}
7836+
7837+
\indexlibraryglobal{vprint_nonunicode}%
7838+
\begin{itemdecl}
7839+
void vprint_nonunicode(FILE* stream, string_view fmt, format_args args);
7840+
\end{itemdecl}
7841+
7842+
\begin{itemdescr}
7843+
\pnum
7844+
\expects
7845+
\tcode{stream} is a valid pointer to an output C stream.
7846+
7847+
\pnum
7848+
\effects
7849+
Writes the result of \tcode{vformat(fmt, args)} to \tcode{stream}.
7850+
7851+
\pnum
7852+
\throws
7853+
Any exception thrown by the call to \tcode{vformat}\iref{format.err.report}.
7854+
\tcode{system_error} if writing to \tcode{stream} fails.
7855+
May throw \tcode{bad_alloc}.
7856+
\end{itemdescr}
7857+
75767858
\rSec1[string.streams]{String-based streams}
75777859

75787860
\rSec2[sstream.syn]{Header \tcode{<sstream>} synopsis}

source/lib-intro.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@
11091109
\tcode{<numeric>} \\
11101110
\tcode{<optional>} \\
11111111
\tcode{<ostream>} \\
1112+
\tcode{<print>} \\
11121113
\tcode{<queue>} \\
11131114
\tcode{<random>} \\
11141115
\tcode{<ranges>} \\

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@
672672
#define @\defnlibxname{cpp_lib_out_ptr}@ 202106L // also in \libheader{memory}
673673
#define @\defnlibxname{cpp_lib_parallel_algorithm}@ 201603L // also in \libheader{algorithm}, \libheader{numeric}
674674
#define @\defnlibxname{cpp_lib_polymorphic_allocator}@ 201902L // also in \libheader{memory_resource}
675+
#define @\defnlibxname{cpp_lib_print}@ 202207L // also in \libheader{print}, \libheader{ostream}
675676
#define @\defnlibxname{cpp_lib_quoted_string_io}@ 201304L // also in \libheader{iomanip}
676677
#define @\defnlibxname{cpp_lib_ranges}@ 202202L
677678
// also in \libheader{algorithm}, \libheader{functional}, \libheader{iterator}, \libheader{memory}, \libheader{ranges}

0 commit comments

Comments
 (0)