Skip to content

Commit 8b535b1

Browse files
committed
P3235R3 std::print more types faster with less memory
1 parent 6d67d20 commit 8b535b1

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

source/iostreams.tex

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7744,14 +7744,14 @@
77447744
If the ordinary literal encoding\iref{lex.charset} is UTF-8, equivalent to:
77457745
\begin{codeblock}
77467746
locksafe
7747-
? vprint_unicode_locking(stream, fmt.str, make_format_args(args...))
7748-
: vprint_unicode(stream, fmt.str, make_format_args(args...));
7747+
? vprint_unicode(stream, fmt.str, make_format_args(args...))
7748+
: vprint_unicode_buffered(stream, fmt.str, make_format_args(args...));
77497749
\end{codeblock}
77507750
Otherwise, equivalent to:
77517751
\begin{codeblock}
77527752
locksafe
7753-
? vprint_nonunicode_locking(stream, fmt.str, make_format_args(args...))
7754-
: vprint_nonunicode(stream, fmt.str, make_format_args(args...));
7753+
? vprint_nonunicode(stream, fmt.str, make_format_args(args...))
7754+
: vprint_nonunicode_buffered(stream, fmt.str, make_format_args(args...));
77557755
\end{codeblock}
77567756
\end{itemdescr}
77577757

@@ -7827,9 +7827,9 @@
78277827
\end{codeblock}
78287828
\end{itemdescr}
78297829

7830-
\indexlibraryglobal{vprint_unicode}%
7830+
\indexlibraryglobal{vprint_unicode_buffered}%
78317831
\begin{itemdecl}
7832-
void vprint_unicode(FILE* stream, string_view fmt, format_args args);
7832+
void vprint_unicode_buffered(FILE* stream, string_view fmt, format_args args);
78337833
\end{itemdecl}
78347834

78357835
\begin{itemdescr}
@@ -7838,13 +7838,13 @@
78387838
Equivalent to:
78397839
\begin{codeblock}
78407840
string out = vformat(fmt, args);
7841-
vprint_unicode_locking(stream, "{}", make_format_args(out));
7841+
vprint_unicode(stream, "{}", make_format_args(out));
78427842
\end{codeblock}
78437843
\end{itemdescr}
78447844

7845-
\indexlibraryglobal{vprint_unicode_locking}%
7845+
\indexlibraryglobal{vprint_unicode}%
78467846
\begin{itemdecl}
7847-
void vprint_unicode_locking(FILE* stream, string_view fmt, format_args args);
7847+
void vprint_unicode(FILE* stream, string_view fmt, format_args args);
78487848
\end{itemdecl}
78497849

78507850
\begin{itemdescr}
@@ -7910,9 +7910,9 @@
79107910
\end{codeblock}
79117911
\end{itemdescr}
79127912

7913-
\indexlibraryglobal{vprint_nonunicode}%
7913+
\indexlibraryglobal{vprint_nonunicode_buffered}%
79147914
\begin{itemdecl}
7915-
void vprint_nonunicode(FILE* stream, string_view fmt, format_args args);
7915+
void vprint_nonunicode_buffered(FILE* stream, string_view fmt, format_args args);
79167916
\end{itemdecl}
79177917

79187918
\begin{itemdescr}
@@ -7921,13 +7921,13 @@
79217921
Equivalent to:
79227922
\begin{codeblock}
79237923
string out = vformat(fmt, args);
7924-
vprint_nonunicode_locking("{}", make_format_args(out));
7924+
vprint_nonunicode("{}", make_format_args(out));
79257925
\end{codeblock}
79267926
\end{itemdescr}
79277927

7928-
\indexlibraryglobal{vprint_nonunicode_locking}%
7928+
\indexlibraryglobal{vprint_nonunicode}%
79297929
\begin{itemdecl}
7930-
void vprint_nonunicode_locking(FILE* stream, string_view fmt, format_args args);
7930+
void vprint_nonunicode(FILE* stream, string_view fmt, format_args args);
79317931
\end{itemdecl}
79327932

79337933
\begin{itemdescr}

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@
728728
#define @\defnlibxname{cpp_lib_out_ptr}@ 202311L // freestanding, also in \libheader{memory}
729729
#define @\defnlibxname{cpp_lib_parallel_algorithm}@ 201603L // also in \libheader{algorithm}, \libheader{numeric}
730730
#define @\defnlibxname{cpp_lib_polymorphic_allocator}@ 201902L // also in \libheader{memory_resource}
731-
#define @\defnlibxname{cpp_lib_print}@ 202403L // also in \libheader{print}, \libheader{ostream}
731+
#define @\defnlibxname{cpp_lib_print}@ 202406L // also in \libheader{print}, \libheader{ostream}
732732
#define @\defnlibxname{cpp_lib_quoted_string_io}@ 201304L // also in \libheader{iomanip}
733733
#define @\defnlibxname{cpp_lib_ranges}@ 202302L
734734
// also in \libheader{algorithm}, \libheader{functional}, \libheader{iterator}, \libheader{memory}, \libheader{ranges}

source/time.tex

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10824,6 +10824,27 @@
1082410824
\end{codeblock}
1082510825
\end{example}
1082610826

10827+
\pnum
10828+
For \tcode{chrono::duration}
10829+
the library only provides the following specialization
10830+
of \tcode{enable_nonlocking_formatter_optimization}:
10831+
\begin{codeblock}
10832+
template<class Rep, class Period>
10833+
inline constexpr bool enable_nonlocking_formatter_optimization<
10834+
chrono::duration<Rep, Period>> =
10835+
enable_nonlocking_formatter_optimization<Rep>;
10836+
\end{codeblock}
10837+
10838+
\pnum
10839+
For \tcode{chrono::zoned_time}
10840+
the library only provides the following specialization of
10841+
\tcode{enable_nonlocking_formatter_optimization}:
10842+
\begin{codeblock}
10843+
template<class Duration>
10844+
inline constexpr bool enable_nonlocking_formatter_optimization<
10845+
chrono::zoned_time<Duration, const std::chrono::time_zone*>> = true;
10846+
\end{codeblock}
10847+
1082710848
\indexlibrary{\idxcode{formatter}!specializations!\idxcode{chrono::sys_time}}%
1082810849
\begin{itemdecl}
1082910850
template<class Duration, class charT>

source/utilities.tex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15821,6 +15821,10 @@
1582115821
@\libconcept{formattable}@<ranges::range_reference_t<R>, charT>
1582215822
struct formatter<R, charT> : @\exposid{range-default-formatter}@<format_kind<R>, R, charT> { };
1582315823

15824+
template<ranges::input_range R>
15825+
requires (format_kind<R> != range_format::disabled)
15826+
inline constexpr bool enable_nonlocking_formatter_optimization<R> = false;
15827+
1582415828
// \ref{format.arguments}, arguments
1582515829
// \ref{format.arg}, class template \tcode{basic_format_arg}
1582615830
template<class Context> class basic_format_arg;
@@ -17139,9 +17143,10 @@
1713917143
interpret the format specification
1714017144
as a \fmtgrammarterm{std-format-spec}
1714117145
as described in \ref{format.string.std}.
17142-
In addition,
17143-
for each type \tcode{T} for which
17144-
a \tcode{formatter} specialization is provided above,
17146+
17147+
\pnum
17148+
Unless specified otherwise, for each type \tcode{T} for which
17149+
a \tcode{formatter} specialization is provided by the library,
1714517150
each of the headers provides the following specialization:
1714617151
\begin{codeblock}
1714717152
template<> inline constexpr bool enable_nonlocking_formatter_optimization<T> = true;
@@ -18714,6 +18719,10 @@
1871418719
typename FormatContext::iterator
1871518720
format(@\seebelow@& elems, FormatContext& ctx) const;
1871618721
};
18722+
18723+
template<class... Ts>
18724+
inline constexpr bool enable_nonlocking_formatter_optimization<@\placeholder{pair-or-tuple}@<Ts...>> =
18725+
(enable_nonlocking_formatter_optimization<Ts> && ...);
1871718726
}
1871818727
\end{codeblock}
1871918728

0 commit comments

Comments
 (0)