From Jason Turner

[format.arguments]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp47k9rbqj/{from.md → to.md} +32 -26
tmp/tmp47k9rbqj/{from.md → to.md} RENAMED
@@ -8,11 +8,11 @@ namespace std {
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>,
@@ -22,10 +22,15 @@ namespace std {
22
 
23
  public:
24
  basic_format_arg() noexcept;
25
 
26
  explicit operator bool() const noexcept;
 
 
 
 
 
27
  };
28
  }
29
  ```
30
 
31
  An instance of `basic_format_arg` provides access to a formatting
@@ -45,17 +50,17 @@ template<class T> explicit basic_format_arg(T& v) noexcept;
45
  ```
46
 
47
  *Constraints:* `T` satisfies `formattable-with<Context>`.
48
 
49
  *Preconditions:* If `decay_t<T>` is `char_type*` or `const char_type*`,
50
- `static_cast<const char_type*>(v)` points to a NTCTS [[defns.ntcts]].
51
 
52
  *Effects:* Let `TD` be `remove_const_t<T>`.
53
 
54
  - If `TD` is `bool` or `char_type`, initializes `value` with `v`;
55
  - otherwise, if `TD` is `char` and `char_type` is `wchar_t`, initializes
56
- `value` with `static_cast<wchar_t>(v)`;
57
  - otherwise, if `TD` is a signed integer type [[basic.fundamental]] and
58
  `sizeof(TD) <= sizeof(int)`, initializes `value` with
59
  `static_cast<int>(v)`;
60
  - otherwise, if `TD` is an unsigned integer type and
61
  `sizeof(TD) <= sizeof(unsigned int)`, initializes `value` with
@@ -86,10 +91,26 @@ is ill-formed unless the user provides an enabled specialization of
86
  explicit operator bool() const noexcept;
87
  ```
88
 
89
  *Returns:* `!holds_alternative<monostate>(value)`.
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  The class `handle` allows formatting an object of a user-defined type.
92
 
93
  ``` cpp
94
  namespace std {
95
  template<class Context>
@@ -98,12 +119,10 @@ namespace std {
98
  void (*format_)(basic_format_parse_context<char_type>&,
99
  Context&, const void*); // exposition only
100
 
101
  template<class T> explicit handle(T& val) noexcept; // exposition only
102
 
103
- friend class basic_format_arg<Context>; // exposition only
104
-
105
  public:
106
  void format(basic_format_parse_context<char_type>&, Context& ctx) const;
107
  };
108
  }
109
  ```
@@ -136,18 +155,10 @@ Let
136
  void format(basic_format_parse_context<char_type>& parse_ctx, Context& format_ctx) const;
137
  ```
138
 
139
  *Effects:* Equivalent to: `format_(parse_ctx, format_ctx, ptr_);`
140
 
141
- ``` cpp
142
- template<class Visitor, class Context>
143
- decltype(auto) visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
144
- ```
145
-
146
- *Effects:* Equivalent to:
147
- `return visit(std::forward<Visitor>(vis), arg.value);`
148
-
149
  #### Class template *`format-arg-store`* <a id="format.arg.store">[[format.arg.store]]</a>
150
 
151
  ``` cpp
152
  namespace std {
153
  template<class Context, class... Args>
@@ -159,25 +170,25 @@ namespace std {
159
 
160
  An instance of *`format-arg-store`* stores formatting arguments.
161
 
162
  ``` cpp
163
  template<class Context = format_context, class... Args>
164
- format-arg-store<Context, Args...> make_format_args(Args&&... fmt_args);
165
  ```
166
 
167
  *Preconditions:* The type
168
- `typename Context::template formatter_type<remove_cvref_t<``Tᵢ``>>`
169
  meets the requirements [[formatter.requirements]] for each `Tᵢ` in
170
  `Args`.
171
 
172
  *Returns:* An object of type *`format-arg-store`*`<Context, Args...>`
173
  whose *args* data member is initialized with
174
  `{basic_format_arg<Context>(fmt_args)...}`.
175
 
176
  ``` cpp
177
  template<class... Args>
178
- format-arg-store<wformat_context, Args...> make_wformat_args(Args&&... args);
179
  ```
180
 
181
  *Effects:* Equivalent to:
182
  `return make_format_args<wformat_context>(args...);`
183
 
@@ -189,12 +200,10 @@ namespace std {
189
  class basic_format_args {
190
  size_t size_; // exposition only
191
  const basic_format_arg<Context>* data_; // exposition only
192
 
193
  public:
194
- basic_format_args() noexcept;
195
-
196
  template<class... Args>
197
  basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
198
 
199
  basic_format_arg<Context> get(size_t i) const noexcept;
200
  };
@@ -203,22 +212,19 @@ namespace std {
203
  basic_format_args(format-arg-store<Context, Args...>) -> basic_format_args<Context>;
204
  }
205
  ```
206
 
207
  An instance of `basic_format_args` provides access to formatting
208
- arguments. Implementations should optimize the representation of
209
- `basic_format_args` for a small number of formatting arguments.
 
 
 
210
 
211
  [*Note 1*: For example, by storing indices of type alternatives
212
  separately from values and packing the former. — *end note*]
213
 
214
- ``` cpp
215
- basic_format_args() noexcept;
216
- ```
217
-
218
- *Effects:* Initializes `size_` with `0`.
219
-
220
  ``` cpp
221
  template<class... Args>
222
  basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
223
  ```
224
 
 
8
  class basic_format_arg {
9
  public:
10
  class handle;
11
 
12
  private:
13
+ using char_type = 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>,
 
22
 
23
  public:
24
  basic_format_arg() noexcept;
25
 
26
  explicit operator bool() const noexcept;
27
+
28
+ template<class Visitor>
29
+ decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
30
+ template<class R, class Visitor>
31
+ R visit(this basic_format_arg arg, Visitor&& vis);
32
  };
33
  }
34
  ```
35
 
36
  An instance of `basic_format_arg` provides access to a formatting
 
50
  ```
51
 
52
  *Constraints:* `T` satisfies `formattable-with<Context>`.
53
 
54
  *Preconditions:* If `decay_t<T>` is `char_type*` or `const char_type*`,
55
+ `static_cast<const char_type*>(v)` points to an NTCTS [[defns.ntcts]].
56
 
57
  *Effects:* Let `TD` be `remove_const_t<T>`.
58
 
59
  - If `TD` is `bool` or `char_type`, initializes `value` with `v`;
60
  - otherwise, if `TD` is `char` and `char_type` is `wchar_t`, initializes
61
+ `value` with `static_cast<wchar_t>(static_cast<unsigned char>(v))`;
62
  - otherwise, if `TD` is a signed integer type [[basic.fundamental]] and
63
  `sizeof(TD) <= sizeof(int)`, initializes `value` with
64
  `static_cast<int>(v)`;
65
  - otherwise, if `TD` is an unsigned integer type and
66
  `sizeof(TD) <= sizeof(unsigned int)`, initializes `value` with
 
91
  explicit operator bool() const noexcept;
92
  ```
93
 
94
  *Returns:* `!holds_alternative<monostate>(value)`.
95
 
96
+ ``` cpp
97
+ template<class Visitor>
98
+ decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
99
+ ```
100
+
101
+ *Effects:* Equivalent to:
102
+ `return arg.value.visit(std::forward<Visitor>(vis));`
103
+
104
+ ``` cpp
105
+ template<class R, class Visitor>
106
+ R visit(this basic_format_arg arg, Visitor&& vis);
107
+ ```
108
+
109
+ *Effects:* Equivalent to:
110
+ `return arg.value.visit<R>(std::forward<Visitor>(vis));`
111
+
112
  The class `handle` allows formatting an object of a user-defined type.
113
 
114
  ``` cpp
115
  namespace std {
116
  template<class Context>
 
119
  void (*format_)(basic_format_parse_context<char_type>&,
120
  Context&, const void*); // exposition only
121
 
122
  template<class T> explicit handle(T& val) noexcept; // exposition only
123
 
 
 
124
  public:
125
  void format(basic_format_parse_context<char_type>&, Context& ctx) const;
126
  };
127
  }
128
  ```
 
155
  void format(basic_format_parse_context<char_type>& parse_ctx, Context& format_ctx) const;
156
  ```
157
 
158
  *Effects:* Equivalent to: `format_(parse_ctx, format_ctx, ptr_);`
159
 
 
 
 
 
 
 
 
 
160
  #### Class template *`format-arg-store`* <a id="format.arg.store">[[format.arg.store]]</a>
161
 
162
  ``` cpp
163
  namespace std {
164
  template<class Context, class... Args>
 
170
 
171
  An instance of *`format-arg-store`* stores formatting arguments.
172
 
173
  ``` cpp
174
  template<class Context = format_context, class... Args>
175
+ format-arg-store<Context, Args...> make_format_args(Args&... fmt_args);
176
  ```
177
 
178
  *Preconditions:* The type
179
+ `typename Context::template formatter_type<remove_const_t<``Tᵢ``>>`
180
  meets the requirements [[formatter.requirements]] for each `Tᵢ` in
181
  `Args`.
182
 
183
  *Returns:* An object of type *`format-arg-store`*`<Context, Args...>`
184
  whose *args* data member is initialized with
185
  `{basic_format_arg<Context>(fmt_args)...}`.
186
 
187
  ``` cpp
188
  template<class... Args>
189
+ format-arg-store<wformat_context, Args...> make_wformat_args(Args&... args);
190
  ```
191
 
192
  *Effects:* Equivalent to:
193
  `return make_format_args<wformat_context>(args...);`
194
 
 
200
  class basic_format_args {
201
  size_t size_; // exposition only
202
  const basic_format_arg<Context>* data_; // exposition only
203
 
204
  public:
 
 
205
  template<class... Args>
206
  basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
207
 
208
  basic_format_arg<Context> get(size_t i) const noexcept;
209
  };
 
212
  basic_format_args(format-arg-store<Context, Args...>) -> basic_format_args<Context>;
213
  }
214
  ```
215
 
216
  An instance of `basic_format_args` provides access to formatting
217
+ arguments.
218
+
219
+ *Recommended practice:* Implementations should optimize the
220
+ representation of `basic_format_args` for a small number of formatting
221
+ arguments.
222
 
223
  [*Note 1*: For example, by storing indices of type alternatives
224
  separately from values and packing the former. — *end note*]
225
 
 
 
 
 
 
 
226
  ``` cpp
227
  template<class... Args>
228
  basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
229
  ```
230