From Jason Turner

[format.arg]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpp2z0b9oz/{from.md → to.md} +202 -0
tmp/tmpp2z0b9oz/{from.md → to.md} RENAMED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class template `basic_format_arg` <a id="format.arg">[[format.arg]]</a>
2
+
3
+ ``` cpp
4
+ namespace std {
5
+ template<class Context>
6
+ class basic_format_arg {
7
+ public:
8
+ class handle;
9
+
10
+ private:
11
+ using char_type = typename Context::char_type; // exposition only
12
+
13
+ variant<monostate, bool, char_type,
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;
42
+ };
43
+ }
44
+ ```
45
+
46
+ An instance of `basic_format_arg` provides access to a formatting
47
+ argument for user-defined formatters.
48
+
49
+ The behavior of a program that adds specializations of
50
+ `basic_format_arg` is undefined.
51
+
52
+ ``` cpp
53
+ 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
149
+ explicit operator bool() const noexcept;
150
+ ```
151
+
152
+ *Returns:* `!holds_alternative<monostate>(value)`.
153
+
154
+ The class `handle` allows formatting an object of a user-defined type.
155
+
156
+ ``` cpp
157
+ namespace std {
158
+ template<class Context>
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;
191
+ ```
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
+