Skip to content

Commit b973c47

Browse files
authored
Merge 2023-02 LWG Motion 12
P2693R1 Formatting thread::id and stacktrace
2 parents 368bc96 + b659879 commit b973c47

File tree

5 files changed

+98
-11
lines changed

5 files changed

+98
-11
lines changed

source/diagnostics.tex

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,10 @@
17441744
template<class Allocator>
17451745
ostream& operator<<(ostream& os, const basic_stacktrace<Allocator>& st);
17461746

1747+
// \ref{stacktrace.format}, formatting support
1748+
template<> struct formatter<stacktrace_entry>;
1749+
template<class Allocator> struct formatter<basic_stacktrace<Allocator>>;
1750+
17471751
namespace pmr {
17481752
using stacktrace = basic_stacktrace<polymorphic_allocator<stacktrace_entry>>;
17491753
}
@@ -2396,6 +2400,48 @@
23962400
Equivalent to: \tcode{return os << to_string(st);}
23972401
\end{itemdescr}
23982402

2403+
\rSec3[stacktrace.format]{Formatting support}
2404+
2405+
\begin{itemdecl}
2406+
template<> struct formatter<stacktrace_entry>;
2407+
\end{itemdecl}
2408+
2409+
\begin{itemdescr}
2410+
\pnum
2411+
\tcode{formatter<stacktrace_entry>} interprets \fmtgrammarterm{format-spec}
2412+
as a \fmtgrammarterm{stacktrace-entry-format-spec}.
2413+
The syntax of format specifications is as follows:
2414+
2415+
\begin{ncbnf}
2416+
\fmtnontermdef{stacktrace-entry-format-spec}\br
2417+
\opt{fill-and-align} \opt{width}
2418+
\end{ncbnf}
2419+
2420+
\begin{note}
2421+
The productions \fmtgrammarterm{fill-and-align} and \fmtgrammarterm{width}
2422+
are described in \ref{format.string.std}.
2423+
\end{note}
2424+
2425+
\pnum
2426+
A \tcode{stacktrace_entry} object \tcode{se} is formatted as if by
2427+
copying \tcode{to_string(se)} through the output iterator of the context
2428+
with additional padding and adjustments as specified by the format specifiers.
2429+
\end{itemdescr}
2430+
2431+
\begin{itemdecl}
2432+
template<class Allocator> struct formatter<basic_stacktrace<Allocator>>;
2433+
\end{itemdecl}
2434+
2435+
\begin{itemdescr}
2436+
\pnum
2437+
For \tcode{formatter<basic_stacktrace<Allocator>>},
2438+
\fmtgrammarterm{format-spec} is empty.
2439+
2440+
\pnum
2441+
A \tcode{basic_stacktrace} object \tcode{s} is formatted as if by
2442+
copying \tcode{to_string(s)} through the output iterator of the context.
2443+
\end{itemdescr}
2444+
23992445
\rSec3[stacktrace.basic.hash]{Hash support}
24002446

24012447
\begin{itemdecl}

source/macros.tex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@
253253
% Usage: \defnadjx{scalar}{types}{type}
254254
\newcommand{\defnadjx}[3]{\indextext{#1 #3|see{#3, #1}}\indexdefn{#3!#1}\textit{#1 #2}}
255255

256+
% Macros used for the grammar of std::format format specifications.
257+
% FIXME: For now, keep the format grammar productions out of the index, since
258+
% they conflict with the main grammar.
259+
% Consider renaming these en masse (to fmt-* ?) to avoid this problem.
260+
\newcommand{\fmtnontermdef}[1]{{\BnfNontermshape#1\itcorr}\textnormal{:}}
261+
\newcommand{\fmtgrammarterm}[1]{\gterm{#1}}
262+
256263
%%--------------------------------------------------
257264
%% allow line break if needed for justification
258265
%%--------------------------------------------------

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@
624624
#define @\defnlibxname{cpp_lib_flat_set}@ 202207L // also in \libheader{flat_set}
625625
#define @\defnlibxname{cpp_lib_format}@ 202207L // also in \libheader{format}
626626
#define @\defnlibxname{cpp_lib_format_ranges}@ 202207L // also in \libheader{format}
627+
#define @\defnlibxname{cpp_lib_formatters}@ 202302L // also in \libheader{stacktrace}, \libheader{thread}
627628
#define @\defnlibxname{cpp_lib_forward_like}@ 202207L // also in \libheader{utility}
628629
#define @\defnlibxname{cpp_lib_gcd_lcm}@ 201606L // also in \libheader{numeric}
629630
#define @\defnlibxname{cpp_lib_generator}@ 202207L // also in \libheader{generator}

source/threads.tex

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,8 @@
12041204
basic_ostream<charT, traits>&
12051205
operator<<(basic_ostream<charT, traits>& out, thread::id id);
12061206

1207+
template<class charT> struct formatter<thread::id, charT>;
1208+
12071209
// hash support
12081210
template<class T> struct hash;
12091211
template<> struct hash<thread::id>;
@@ -1220,6 +1222,16 @@
12201222
equal to the \tcode{thread::id} object of any \tcode{thread} object that
12211223
does not represent threads of execution.
12221224

1225+
\pnum
1226+
The \defn{text representation} for
1227+
the character type \tcode{charT} of an object of type \tcode{thread::id}
1228+
is an unspecified sequence of \tcode{charT} such that,
1229+
for two objects of type \tcode{thread::id} \tcode{x} and \tcode{y},
1230+
if \tcode{x == y} is \tcode{true},
1231+
the \tcode{thread::id} objects have the same text representation, and
1232+
if \tcode{x != y} is \tcode{true},
1233+
the \tcode{thread::id} objects have distinct text representations.
1234+
12231235
\pnum
12241236
\tcode{thread::id} is a trivially copyable class\iref{class.prop}.
12251237
The library may reuse the value of a \tcode{thread::id} of a terminated thread that can no longer be joined.
@@ -1283,17 +1295,44 @@
12831295
\begin{itemdescr}
12841296
\pnum
12851297
\effects
1286-
Inserts an unspecified text representation of \tcode{id} into
1287-
\tcode{out}. For two objects of type \tcode{thread::id} \tcode{x} and \tcode{y},
1288-
if \tcode{x == y} the \tcode{thread::id} objects have the same text
1289-
representation and if \tcode{x != y} the \tcode{thread::id} objects have
1290-
distinct text representations.
1298+
Inserts the text representation for \tcode{charT} of \tcode{id} into
1299+
\tcode{out}.
12911300

12921301
\pnum
12931302
\returns
12941303
\tcode{out}.
12951304
\end{itemdescr}
12961305

1306+
\indexlibrary{\idxcode{formatter}!specializations!\idxcode{thread::id}}%
1307+
\begin{itemdecl}
1308+
template<class charT> struct formatter<thread::id, charT>;
1309+
\end{itemdecl}
1310+
1311+
\begin{itemdescr}
1312+
\pnum
1313+
\tcode{formatter<thread::id, charT>} interprets \fmtgrammarterm{format-spec}
1314+
as a \fmtgrammarterm{thread-id-format-spec}.
1315+
The syntax of format specifications is as follows:
1316+
1317+
\begin{ncbnf}
1318+
\fmtnontermdef{thread-id-format-spec}\br
1319+
\opt{fill-and-align} \opt{width}
1320+
\end{ncbnf}
1321+
1322+
\begin{note}
1323+
The productions \fmtgrammarterm{fill-and-align} and \fmtgrammarterm{width}
1324+
are described in \ref{format.string.std}.
1325+
\end{note}
1326+
1327+
\pnum
1328+
If the \fmtgrammarterm{align} option is omitted it defaults to \tcode{>}.
1329+
1330+
\pnum
1331+
A \tcode{thread::id} object is formatted by
1332+
writing its text representation for \tcode{charT} to the output
1333+
with additional padding and adjustments as specified by the format specifiers.
1334+
\end{itemdescr}
1335+
12971336
\indexlibrarymember{hash}{thread::id}%
12981337
\begin{itemdecl}
12991338
template<> struct hash<thread::id>;

source/utilities.tex

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14630,12 +14630,6 @@
1463014630

1463114631
\rSec3[format.string.general]{In general}
1463214632

14633-
% FIXME: For now, keep the format grammar productions out of the index, since
14634-
% they conflict with the main grammar.
14635-
% Consider renaming these en masse (to fmt-* ?) to avoid this problem.
14636-
\newcommand{\fmtnontermdef}[1]{{\BnfNontermshape#1\itcorr}\textnormal{:}}
14637-
\newcommand{\fmtgrammarterm}[1]{\gterm{#1}}
14638-
1463914633
\pnum
1464014634
A \defn{format string} for arguments \tcode{args} is
1464114635
a (possibly empty) sequence of

0 commit comments

Comments
 (0)