From Jason Turner

[format.arg]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpcqjbnovm/{from.md → to.md} +41 -97
tmp/tmpcqjbnovm/{from.md → to.md} RENAMED
@@ -14,28 +14,11 @@ namespace std {
14
  int, unsigned int, long long int, unsigned long long int,
15
  float, double, long double,
16
  const char_type*, basic_string_view<char_type>,
17
  const void*, handle> value; // exposition only
18
 
19
- template<class T> explicit basic_format_arg(const T& v) noexcept; // exposition only
20
- explicit basic_format_arg(float n) noexcept; // exposition only
21
- explicit basic_format_arg(double n) noexcept; // exposition only
22
- explicit basic_format_arg(long double n) noexcept; // exposition only
23
- explicit basic_format_arg(const char_type* s); // exposition only
24
-
25
- template<class traits>
26
- explicit basic_format_arg(
27
- basic_string_view<char_type, traits> s) noexcept; // exposition only
28
-
29
- template<class traits, class Allocator>
30
- explicit basic_format_arg(
31
- const basic_string<char_type, traits, Allocator>& s) noexcept; // exposition only
32
-
33
- explicit basic_format_arg(nullptr_t) noexcept; // exposition only
34
-
35
- template<class T>
36
- explicit basic_format_arg(const T* p) noexcept; // exposition only
37
 
38
  public:
39
  basic_format_arg() noexcept;
40
 
41
  explicit operator bool() const noexcept;
@@ -54,95 +37,47 @@ basic_format_arg() noexcept;
54
  ```
55
 
56
  *Ensures:* `!(*this)`.
57
 
58
  ``` cpp
59
- template<class T> explicit basic_format_arg(const T& v) noexcept;
60
  ```
61
 
62
- *Constraints:* The template specialization
63
 
64
- ``` cpp
65
- typename Context::template formatter_type<T>
66
- ```
67
-
68
- meets the requirements [[formatter.requirements]]. The extent to which
69
- an implementation determines that the specialization meets the
70
- requirements is unspecified, except that as a minimum the expression
71
-
72
- ``` cpp
73
- typename Context::template formatter_type<T>()
74
- .format(declval<const T&>(), declval<Context&>())
75
- ```
76
-
77
- shall be well-formed when treated as an unevaluated operand.
78
 
79
- *Effects:*
80
 
81
- - if `T` is `bool` or `char_type`, initializes `value` with `v`;
82
- - otherwise, if `T` is `char` and `char_type` is `wchar_t`, initializes
83
  `value` with `static_cast<wchar_t>(v)`;
84
- - otherwise, if `T` is a signed integer type [[basic.fundamental]] and
85
- `sizeof(T) <= sizeof(int)`, initializes `value` with
86
  `static_cast<int>(v)`;
87
- - otherwise, if `T` is an unsigned integer type and
88
- `sizeof(T) <= sizeof(unsigned int)`, initializes `value` with
89
  `static_cast<unsigned int>(v)`;
90
- - otherwise, if `T` is a signed integer type and
91
- `sizeof(T) <= sizeof(long long int)`, initializes `value` with
92
  `static_cast<long long int>(v)`;
93
- - otherwise, if `T` is an unsigned integer type and
94
- `sizeof(T) <= sizeof(unsigned long long int)`, initializes `value`
95
  with `static_cast<unsigned long long int>(v)`;
 
 
 
 
 
 
 
 
 
 
96
  - otherwise, initializes `value` with `handle(v)`.
97
 
98
- ``` cpp
99
- explicit basic_format_arg(float n) noexcept;
100
- explicit basic_format_arg(double n) noexcept;
101
- explicit basic_format_arg(long double n) noexcept;
102
- ```
103
-
104
- *Effects:* Initializes `value` with `n`.
105
-
106
- ``` cpp
107
- explicit basic_format_arg(const char_type* s);
108
- ```
109
-
110
- *Preconditions:* `s` points to a NTCTS [[defns.ntcts]].
111
-
112
- *Effects:* Initializes `value` with `s`.
113
-
114
- ``` cpp
115
- template<class traits>
116
- explicit basic_format_arg(basic_string_view<char_type, traits> s) noexcept;
117
- ```
118
-
119
- *Effects:* Initializes `value` with `s`.
120
-
121
- ``` cpp
122
- template<class traits, class Allocator>
123
- explicit basic_format_arg(
124
- const basic_string<char_type, traits, Allocator>& s) noexcept;
125
- ```
126
-
127
- *Effects:* Initializes `value` with
128
- `basic_string_view<char_type>(s.data(), s.size())`.
129
-
130
- ``` cpp
131
- explicit basic_format_arg(nullptr_t) noexcept;
132
- ```
133
-
134
- *Effects:* Initializes `value` with `static_cast<const void*>(nullptr)`.
135
-
136
- ``` cpp
137
- template<class T> explicit basic_format_arg(const T* p) noexcept;
138
- ```
139
-
140
- *Constraints:* `is_void_v<T>` is `true`.
141
-
142
- *Effects:* Initializes `value` with `p`.
143
-
144
  [*Note 1*: Constructing `basic_format_arg` from a pointer to a member
145
  is ill-formed unless the user provides an enabled specialization of
146
  `formatter` for that pointer to member type. — *end note*]
147
 
148
  ``` cpp
@@ -159,32 +94,41 @@ namespace std {
159
  class basic_format_arg<Context>::handle {
160
  const void* ptr_; // exposition only
161
  void (*format_)(basic_format_parse_context<char_type>&,
162
  Context&, const void*); // exposition only
163
 
164
- template<class T> explicit handle(const T& val) noexcept; // exposition only
165
 
166
  friend class basic_format_arg<Context>; // exposition only
167
 
168
  public:
169
  void format(basic_format_parse_context<char_type>&, Context& ctx) const;
170
  };
171
  }
172
  ```
173
 
174
  ``` cpp
175
- template<class T> explicit handle(const T& val) noexcept;
176
  ```
177
 
 
 
 
 
 
 
 
 
178
  *Effects:* Initializes `ptr_` with `addressof(val)` and `format_` with
179
 
180
  ``` cpp
181
  [](basic_format_parse_context<char_type>& parse_ctx,
182
  Context& format_ctx, const void* ptr) {
183
- typename Context::template formatter_type<T> f;
184
  parse_ctx.advance_to(f.parse(parse_ctx));
185
- format_ctx.advance_to(f.format(*static_cast<const T*>(ptr), format_ctx));
 
186
  }
187
  ```
188
 
189
  ``` cpp
190
  void format(basic_format_parse_context<char_type>& parse_ctx, Context& format_ctx) const;
@@ -192,11 +136,11 @@ void format(basic_format_parse_context<char_type>& parse_ctx, Context& format_ct
192
 
193
  *Effects:* Equivalent to: `format_(parse_ctx, format_ctx, ptr_);`
194
 
195
  ``` cpp
196
  template<class Visitor, class Context>
197
- see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
198
  ```
199
 
200
  *Effects:* Equivalent to:
201
- `return visit(forward<Visitor>(vis), arg.value);`
202
 
 
14
  int, unsigned int, long long int, unsigned long long int,
15
  float, double, long double,
16
  const char_type*, basic_string_view<char_type>,
17
  const void*, handle> value; // exposition only
18
 
19
+ template<class T> explicit basic_format_arg(T& v) noexcept; // exposition only
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  public:
22
  basic_format_arg() noexcept;
23
 
24
  explicit operator bool() const noexcept;
 
37
  ```
38
 
39
  *Ensures:* `!(*this)`.
40
 
41
  ``` cpp
42
+ template<class T> explicit basic_format_arg(T& v) noexcept;
43
  ```
44
 
45
+ *Constraints:* `T` satisfies `formattable-with<Context>`.
46
 
47
+ *Preconditions:* If `decay_t<T>` is `char_type*` or `const char_type*`,
48
+ `static_cast<const char_type*>(v)` points to a NTCTS [[defns.ntcts]].
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
+ *Effects:* Let `TD` be `remove_const_t<T>`.
51
 
52
+ - If `TD` is `bool` or `char_type`, initializes `value` with `v`;
53
+ - otherwise, if `TD` is `char` and `char_type` is `wchar_t`, initializes
54
  `value` with `static_cast<wchar_t>(v)`;
55
+ - otherwise, if `TD` is a signed integer type [[basic.fundamental]] and
56
+ `sizeof(TD) <= sizeof(int)`, initializes `value` with
57
  `static_cast<int>(v)`;
58
+ - otherwise, if `TD` is an unsigned integer type and
59
+ `sizeof(TD) <= sizeof(unsigned int)`, initializes `value` with
60
  `static_cast<unsigned int>(v)`;
61
+ - otherwise, if `TD` is a signed integer type and
62
+ `sizeof(TD) <= sizeof(long long int)`, initializes `value` with
63
  `static_cast<long long int>(v)`;
64
+ - otherwise, if `TD` is an unsigned integer type and
65
+ `sizeof(TD) <= sizeof(unsigned long long int)`, initializes `value`
66
  with `static_cast<unsigned long long int>(v)`;
67
+ - otherwise, if `TD` is a standard floating-point type, initializes
68
+ `value` with `v`;
69
+ - otherwise, if `TD` is a specialization of `basic_string_view` or
70
+ `basic_string` and `TD::value_type` is `char_type`, initializes
71
+ `value` with `basic_string_view<char_type>(v.data(), v.size())`;
72
+ - otherwise, if `decay_t<TD>` is `char_type*` or `const char_type*`,
73
+ initializes `value` with `static_cast<const char_type*>(v)`;
74
+ - otherwise, if `is_void_v<remove_pointer_t<TD>>` is `true` or
75
+ `is_null_pointer_v<TD>` is `true`, initializes `value` with
76
+ `static_cast<const void*>(v)`;
77
  - otherwise, initializes `value` with `handle(v)`.
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  [*Note 1*: Constructing `basic_format_arg` from a pointer to a member
80
  is ill-formed unless the user provides an enabled specialization of
81
  `formatter` for that pointer to member type. — *end note*]
82
 
83
  ``` cpp
 
94
  class basic_format_arg<Context>::handle {
95
  const void* ptr_; // exposition only
96
  void (*format_)(basic_format_parse_context<char_type>&,
97
  Context&, const void*); // exposition only
98
 
99
+ template<class T> explicit handle(T& val) noexcept; // exposition only
100
 
101
  friend class basic_format_arg<Context>; // exposition only
102
 
103
  public:
104
  void format(basic_format_parse_context<char_type>&, Context& ctx) const;
105
  };
106
  }
107
  ```
108
 
109
  ``` cpp
110
+ template<class T> explicit handle(T& val) noexcept;
111
  ```
112
 
113
+ Let
114
+
115
+ - `TD` be `remove_const_t<T>`,
116
+ - `TQ` be `const TD` if `const TD` satisfies `formattable-with<Context>`
117
+ and `TD` otherwise.
118
+
119
+ *Mandates:* `TQ` satisfies `formattable-with<Context>`.
120
+
121
  *Effects:* Initializes `ptr_` with `addressof(val)` and `format_` with
122
 
123
  ``` cpp
124
  [](basic_format_parse_context<char_type>& parse_ctx,
125
  Context& format_ctx, const void* ptr) {
126
+ typename Context::template formatter_type<TD> f;
127
  parse_ctx.advance_to(f.parse(parse_ctx));
128
+ format_ctx.advance_to(f.format(*const_cast<TQ*>(static_cast<const TD*>(ptr)),
129
+ format_ctx));
130
  }
131
  ```
132
 
133
  ``` cpp
134
  void format(basic_format_parse_context<char_type>& parse_ctx, Context& format_ctx) const;
 
136
 
137
  *Effects:* Equivalent to: `format_(parse_ctx, format_ctx, ptr_);`
138
 
139
  ``` cpp
140
  template<class Visitor, class Context>
141
+ decltype(auto) visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
142
  ```
143
 
144
  *Effects:* Equivalent to:
145
+ `return visit(std::forward<Visitor>(vis), arg.value);`
146