From Jason Turner

[format.arguments]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp9scplc6k/{from.md → to.md} +284 -0
tmp/tmp9scplc6k/{from.md → to.md} RENAMED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Arguments <a id="format.arguments">[[format.arguments]]</a>
2
+
3
+ #### Class template `basic_format_arg` <a id="format.arg">[[format.arg]]</a>
4
+
5
+ ``` cpp
6
+ namespace std {
7
+ template<class Context>
8
+ class basic_format_arg {
9
+ public:
10
+ class handle;
11
+
12
+ private:
13
+ using char_type = typename Context::char_type; // exposition only
14
+
15
+ variant<monostate, bool, char_type,
16
+ int, unsigned int, long long int, unsigned long long int,
17
+ float, double, long double,
18
+ const char_type*, basic_string_view<char_type>,
19
+ const void*, handle> value; // exposition only
20
+
21
+ template<class T> explicit basic_format_arg(const T& v) noexcept; // exposition only
22
+ explicit basic_format_arg(float n) noexcept; // exposition only
23
+ explicit basic_format_arg(double n) noexcept; // exposition only
24
+ explicit basic_format_arg(long double n) noexcept; // exposition only
25
+ explicit basic_format_arg(const char_type* s); // exposition only
26
+
27
+ template<class traits>
28
+ explicit basic_format_arg(
29
+ basic_string_view<char_type, traits> s) noexcept; // exposition only
30
+
31
+ template<class traits, class Allocator>
32
+ explicit basic_format_arg(
33
+ const basic_string<char_type, traits, Allocator>& s) noexcept; // exposition only
34
+
35
+ explicit basic_format_arg(nullptr_t) noexcept; // exposition only
36
+
37
+ template<class T>
38
+ explicit basic_format_arg(const T* p) noexcept; // exposition only
39
+
40
+ public:
41
+ basic_format_arg() noexcept;
42
+
43
+ explicit operator bool() const noexcept;
44
+ };
45
+ }
46
+ ```
47
+
48
+ An instance of `basic_format_arg` provides access to a formatting
49
+ argument for user-defined formatters.
50
+
51
+ The behavior of a program that adds specializations of
52
+ `basic_format_arg` is undefined.
53
+
54
+ ``` cpp
55
+ basic_format_arg() noexcept;
56
+ ```
57
+
58
+ *Ensures:* `!(*this)`.
59
+
60
+ ``` cpp
61
+ template<class T> explicit basic_format_arg(const T& v) noexcept;
62
+ ```
63
+
64
+ *Constraints:* The template specialization
65
+
66
+ ``` cpp
67
+ typename Context::template formatter_type<T>
68
+ ```
69
+
70
+ meets the requirements [[formatter.requirements]]. The extent to which
71
+ an implementation determines that the specialization meets the
72
+ requirements is unspecified, except that as a minimum the expression
73
+
74
+ ``` cpp
75
+ typename Context::template formatter_type<T>()
76
+ .format(declval<const T&>(), declval<Context&>())
77
+ ```
78
+
79
+ shall be well-formed when treated as an unevaluated operand.
80
+
81
+ *Effects:*
82
+
83
+ - if `T` is `bool` or `char_type`, initializes `value` with `v`;
84
+ - otherwise, if `T` is `char` and `char_type` is `wchar_t`, initializes
85
+ `value` with `static_cast<wchar_t>(v)`;
86
+ - otherwise, if `T` is a signed integer type [[basic.fundamental]] and
87
+ `sizeof(T) <= sizeof(int)`, initializes `value` with
88
+ `static_cast<int>(v)`;
89
+ - otherwise, if `T` is an unsigned integer type and
90
+ `sizeof(T) <= sizeof(unsigned int)`, initializes `value` with
91
+ `static_cast<unsigned int>(v)`;
92
+ - otherwise, if `T` is a signed integer type and
93
+ `sizeof(T) <= sizeof(long long int)`, initializes `value` with
94
+ `static_cast<long long int>(v)`;
95
+ - otherwise, if `T` is an unsigned integer type and
96
+ `sizeof(T) <= sizeof(unsigned long long int)`, initializes `value`
97
+ with `static_cast<unsigned long long int>(v)`;
98
+ - otherwise, initializes `value` with `handle(v)`.
99
+
100
+ ``` cpp
101
+ explicit basic_format_arg(float n) noexcept;
102
+ explicit basic_format_arg(double n) noexcept;
103
+ explicit basic_format_arg(long double n) noexcept;
104
+ ```
105
+
106
+ *Effects:* Initializes `value` with `n`.
107
+
108
+ ``` cpp
109
+ explicit basic_format_arg(const char_type* s);
110
+ ```
111
+
112
+ *Preconditions:* `s` points to a NTCTS [[defns.ntcts]].
113
+
114
+ *Effects:* Initializes `value` with `s`.
115
+
116
+ ``` cpp
117
+ template<class traits>
118
+ explicit basic_format_arg(basic_string_view<char_type, traits> s) noexcept;
119
+ ```
120
+
121
+ *Effects:* Initializes `value` with `s`.
122
+
123
+ ``` cpp
124
+ template<class traits, class Allocator>
125
+ explicit basic_format_arg(
126
+ const basic_string<char_type, traits, Allocator>& s) noexcept;
127
+ ```
128
+
129
+ *Effects:* Initializes `value` with
130
+ `basic_string_view<char_type>(s.data(), s.size())`.
131
+
132
+ ``` cpp
133
+ explicit basic_format_arg(nullptr_t) noexcept;
134
+ ```
135
+
136
+ *Effects:* Initializes `value` with `static_cast<const void*>(nullptr)`.
137
+
138
+ ``` cpp
139
+ template<class T> explicit basic_format_arg(const T* p) noexcept;
140
+ ```
141
+
142
+ *Constraints:* `is_void_v<T>` is `true`.
143
+
144
+ *Effects:* Initializes `value` with `p`.
145
+
146
+ [*Note 1*: Constructing `basic_format_arg` from a pointer to a member
147
+ is ill-formed unless the user provides an enabled specialization of
148
+ `formatter` for that pointer to member type. — *end note*]
149
+
150
+ ``` cpp
151
+ explicit operator bool() const noexcept;
152
+ ```
153
+
154
+ *Returns:* `!holds_alternative<monostate>(value)`.
155
+
156
+ The class `handle` allows formatting an object of a user-defined type.
157
+
158
+ ``` cpp
159
+ namespace std {
160
+ template<class Context>
161
+ class basic_format_arg<Context>::handle {
162
+ const void* ptr_; // exposition only
163
+ void (*format_)(basic_format_parse_context<char_type>&,
164
+ Context&, const void*); // exposition only
165
+
166
+ template<class T> explicit handle(const T& val) noexcept; // exposition only
167
+
168
+ friend class basic_format_arg<Context>; // exposition only
169
+
170
+ public:
171
+ void format(basic_format_parse_context<char_type>&, Context& ctx) const;
172
+ };
173
+ }
174
+ ```
175
+
176
+ ``` cpp
177
+ template<class T> explicit handle(const T& val) noexcept;
178
+ ```
179
+
180
+ *Effects:* Initializes `ptr_` with `addressof(val)` and `format_` with
181
+
182
+ ``` cpp
183
+ [](basic_format_parse_context<char_type>& parse_ctx,
184
+ Context& format_ctx, const void* ptr) {
185
+ typename Context::template formatter_type<T> f;
186
+ parse_ctx.advance_to(f.parse(parse_ctx));
187
+ format_ctx.advance_to(f.format(*static_cast<const T*>(ptr), format_ctx));
188
+ }
189
+ ```
190
+
191
+ ``` cpp
192
+ void format(basic_format_parse_context<char_type>& parse_ctx, Context& format_ctx) const;
193
+ ```
194
+
195
+ *Effects:* Equivalent to: `format_(parse_ctx, format_ctx, ptr_);`
196
+
197
+ ``` cpp
198
+ template<class Visitor, class Context>
199
+ see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
200
+ ```
201
+
202
+ *Effects:* Equivalent to:
203
+ `return visit(forward<Visitor>(vis), arg.value);`
204
+
205
+ #### Class template *`format-arg-store`* <a id="format.arg.store">[[format.arg.store]]</a>
206
+
207
+ ``` cpp
208
+ namespace std {
209
+ template<class Context, class... Args>
210
+ struct format-arg-store { // exposition only
211
+ array<basic_format_arg<Context>, sizeof...(Args)> args;
212
+ };
213
+ }
214
+ ```
215
+
216
+ An instance of *`format-arg-store`* stores formatting arguments.
217
+
218
+ ``` cpp
219
+ template<class Context = format_context, class... Args>
220
+ format-arg-store<Context, Args...> make_format_args(const Args&... args);
221
+ ```
222
+
223
+ *Preconditions:* The type
224
+ `typename Context::template formatter_type<``Tᵢ``>` meets the
225
+ requirements [[formatter.requirements]] for each `Tᵢ` in `Args`.
226
+
227
+ *Returns:* `{basic_format_arg<Context>(args)...}`.
228
+
229
+ ``` cpp
230
+ template<class... Args>
231
+ format-arg-store<wformat_context, Args...> make_wformat_args(const Args&... args);
232
+ ```
233
+
234
+ *Effects:* Equivalent to:
235
+ `return make_format_args<wformat_context>(args...);`
236
+
237
+ #### Class template `basic_format_args` <a id="format.args">[[format.args]]</a>
238
+
239
+ ``` cpp
240
+ namespace std {
241
+ template<class Context>
242
+ class basic_format_args {
243
+ size_t size_; // exposition only
244
+ const basic_format_arg<Context>* data_; // exposition only
245
+
246
+ public:
247
+ basic_format_args() noexcept;
248
+
249
+ template<class... Args>
250
+ basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
251
+
252
+ basic_format_arg<Context> get(size_t i) const noexcept;
253
+ };
254
+ }
255
+ ```
256
+
257
+ An instance of `basic_format_args` provides access to formatting
258
+ arguments.
259
+
260
+ ``` cpp
261
+ basic_format_args() noexcept;
262
+ ```
263
+
264
+ *Effects:* Initializes `size_` with `0`.
265
+
266
+ ``` cpp
267
+ template<class... Args>
268
+ basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
269
+ ```
270
+
271
+ *Effects:* Initializes `size_` with `sizeof...(Args)` and `data_` with
272
+ `store.args.data()`.
273
+
274
+ ``` cpp
275
+ basic_format_arg<Context> get(size_t i) const noexcept;
276
+ ```
277
+
278
+ *Returns:* `i < size_ ? data_[i] : basic_format_arg<Context>()`.
279
+
280
+ [*Note 1*: Implementations are encouraged to optimize the
281
+ representation of `basic_format_args` for small number of formatting
282
+ arguments by storing indices of type alternatives separately from values
283
+ and packing the former. — *end note*]
284
+