From Jason Turner

[format.string.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjdej4kbu/{from.md → to.md} +109 -0
tmp/tmpjdej4kbu/{from.md → to.md} RENAMED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### In general <a id="format.string.general">[[format.string.general]]</a>
2
+
3
+ A *format string* for arguments `args` is a (possibly empty) sequence of
4
+ *replacement fields*, *escape sequences*, and characters other than `{`
5
+ and `}`. Let `charT` be the character type of the format string. Each
6
+ character that is not part of a replacement field or an escape sequence
7
+ is copied unchanged to the output. An escape sequence is one of `{{` or
8
+ `}}`. It is replaced with `{` or `}`, respectively, in the output. The
9
+ syntax of replacement fields is as follows:
10
+
11
+ ``` bnf
12
+ replacement-field
13
+ '{' arg-idₒₚₜ format-specifierₒₚₜ '}'
14
+ ```
15
+
16
+ ``` bnf
17
+ arg-id
18
+ '0'
19
+ positive-integer
20
+ ```
21
+
22
+ ``` bnf
23
+ positive-integer
24
+ nonzero-digit
25
+ positive-integer digit
26
+ ```
27
+
28
+ ``` bnf
29
+ nonnegative-integer
30
+ digit
31
+ nonnegative-integer digit
32
+ ```
33
+
34
+ ``` bnf
35
+ nonzero-digit one of
36
+ '1 2 3 4 5 6 7 8 9'
37
+ ```
38
+
39
+ ``` bnf
40
+ digit one of
41
+ '0 1 2 3 4 5 6 7 8 9'
42
+ ```
43
+
44
+ ``` bnf
45
+ format-specifier
46
+ ':' format-spec
47
+ ```
48
+
49
+ ``` bnf
50
+ format-spec
51
+ as specified by the formatter specialization for the argument type
52
+ ```
53
+
54
+ The *arg-id* field specifies the index of the argument in `args` whose
55
+ value is to be formatted and inserted into the output instead of the
56
+ replacement field. If there is no argument with the index *arg-id* in
57
+ `args`, the string is not a format string for `args`. The optional
58
+ *format-specifier* field explicitly specifies a format for the
59
+ replacement value.
60
+
61
+ [*Example 1*:
62
+
63
+ ``` cpp
64
+ string s = format("{0}-{{", 8); // value of s is "8-{"
65
+ ```
66
+
67
+ — *end example*]
68
+
69
+ If all *arg-id*s in a format string are omitted (including those in the
70
+ *format-spec*, as interpreted by the corresponding `formatter`
71
+ specialization), argument indices 0, 1, 2, … will automatically be used
72
+ in that order. If some *arg-id*s are omitted and some are present, the
73
+ string is not a format string.
74
+
75
+ [*Note 1*: A format string cannot contain a mixture of automatic and
76
+ manual indexing. — *end note*]
77
+
78
+ [*Example 2*:
79
+
80
+ ``` cpp
81
+ string s0 = format("{} to {}", "a", "b"); // OK, automatic indexing
82
+ string s1 = format("{1} to {0}", "a", "b"); // OK, manual indexing
83
+ string s2 = format("{0} to {}", "a", "b"); // not a format string (mixing automatic and manual indexing),
84
+ // throws format_error
85
+ string s3 = format("{} to {1}", "a", "b"); // not a format string (mixing automatic and manual indexing),
86
+ // throws format_error
87
+ ```
88
+
89
+ — *end example*]
90
+
91
+ The *format-spec* field contains *format specifications* that define how
92
+ the value should be presented. Each type can define its own
93
+ interpretation of the *format-spec* field. If *format-spec* does not
94
+ conform to the format specifications for the argument type referred to
95
+ by *arg-id*, the string is not a format string for `args`.
96
+
97
+ [*Example 3*:
98
+
99
+ - For arithmetic, pointer, and string types the *format-spec* is
100
+ interpreted as a *std-format-spec* as described in
101
+ [[format.string.std]].
102
+ - For chrono types the *format-spec* is interpreted as a
103
+ *chrono-format-spec* as described in [[time.format]].
104
+ - For user-defined `formatter` specializations, the behavior of the
105
+ `parse` member function determines how the *format-spec* is
106
+ interpreted.
107
+
108
+ — *end example*]
109
+