tmp/tmp2wivcuvs/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### Formatter specializations <a id="format.formatter.spec">[[format.formatter.spec]]</a>
|
| 2 |
+
|
| 3 |
+
The functions defined in [[format.functions]] use specializations of the
|
| 4 |
+
class template `formatter` to format individual arguments.
|
| 5 |
+
|
| 6 |
+
Let `charT` be either `char` or `wchar_t`. Each specialization of
|
| 7 |
+
`formatter` is either enabled or disabled, as described below.
|
| 8 |
+
|
| 9 |
+
[*Note 1*: Enabled specializations meet the requirements, and disabled
|
| 10 |
+
specializations do not. — *end note*]
|
| 11 |
+
|
| 12 |
+
Each header that declares the template `formatter` provides the
|
| 13 |
+
following enabled specializations:
|
| 14 |
+
|
| 15 |
+
- The specializations
|
| 16 |
+
``` cpp
|
| 17 |
+
template<> struct formatter<char, char>;
|
| 18 |
+
template<> struct formatter<char, wchar_t>;
|
| 19 |
+
template<> struct formatter<wchar_t, wchar_t>;
|
| 20 |
+
```
|
| 21 |
+
- For each `charT`, the string type specializations
|
| 22 |
+
``` cpp
|
| 23 |
+
template<> struct formatter<charT*, charT>;
|
| 24 |
+
template<> struct formatter<const charT*, charT>;
|
| 25 |
+
template<size_t N> struct formatter<const charT[N], charT>;
|
| 26 |
+
template<class traits, class Allocator>
|
| 27 |
+
struct formatter<basic_string<charT, traits, Allocator>, charT>;
|
| 28 |
+
template<class traits>
|
| 29 |
+
struct formatter<basic_string_view<charT, traits>, charT>;
|
| 30 |
+
```
|
| 31 |
+
- For each `charT`, for each cv-unqualified arithmetic type
|
| 32 |
+
`ArithmeticT` other than `char`, `wchar_t`, `char8_t`, `char16_t`, or
|
| 33 |
+
`char32_t`, a specialization
|
| 34 |
+
``` cpp
|
| 35 |
+
template<> struct formatter<ArithmeticT, charT>;
|
| 36 |
+
```
|
| 37 |
+
- For each `charT`, the pointer type specializations
|
| 38 |
+
``` cpp
|
| 39 |
+
template<> struct formatter<nullptr_t, charT>;
|
| 40 |
+
template<> struct formatter<void*, charT>;
|
| 41 |
+
template<> struct formatter<const void*, charT>;
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
The `parse` member functions of these formatters interpret the format
|
| 45 |
+
specification as a *std-format-spec* as described in
|
| 46 |
+
[[format.string.std]].
|
| 47 |
+
|
| 48 |
+
[*Note 2*: Specializations such as `formatter<wchar_t, char>` and
|
| 49 |
+
`formatter<const char*, wchar_t>` that would require implicit multibyte
|
| 50 |
+
/ wide string or character conversion are disabled. — *end note*]
|
| 51 |
+
|
| 52 |
+
For any types `T` and `charT` for which neither the library nor the user
|
| 53 |
+
provides an explicit or partial specialization of the class template
|
| 54 |
+
`formatter`, `formatter<T, charT>` is disabled.
|
| 55 |
+
|
| 56 |
+
If the library provides an explicit or partial specialization of
|
| 57 |
+
`formatter<T, charT>`, that specialization is enabled except as noted
|
| 58 |
+
otherwise.
|
| 59 |
+
|
| 60 |
+
If `F` is a disabled specialization of `formatter`, these values are
|
| 61 |
+
`false`:
|
| 62 |
+
|
| 63 |
+
- `is_default_constructible_v<F>`,
|
| 64 |
+
- `is_copy_constructible_v<F>`,
|
| 65 |
+
- `is_move_constructible_v<F>`,
|
| 66 |
+
- `is_copy_assignable_v<F>`, and
|
| 67 |
+
- `is_move_assignable_v<F>`.
|
| 68 |
+
|
| 69 |
+
An enabled specialization `formatter<T, charT>` meets the requirements
|
| 70 |
+
[[formatter.requirements]].
|
| 71 |
+
|
| 72 |
+
[*Example 1*:
|
| 73 |
+
|
| 74 |
+
``` cpp
|
| 75 |
+
#include <format>
|
| 76 |
+
|
| 77 |
+
enum color { red, green, blue };
|
| 78 |
+
const char* color_names[] = { "red", "green", "blue" };
|
| 79 |
+
|
| 80 |
+
template<> struct std::formatter<color> : std::formatter<const char*> {
|
| 81 |
+
auto format(color c, format_context& ctx) {
|
| 82 |
+
return formatter<const char*>::format(color_names[c], ctx);
|
| 83 |
+
}
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
struct err {};
|
| 87 |
+
|
| 88 |
+
std::string s0 = std::format("{}", 42); // OK, library-provided formatter
|
| 89 |
+
std::string s1 = std::format("{}", L"foo"); // error: disabled formatter
|
| 90 |
+
std::string s2 = std::format("{}", red); // OK, user-provided formatter
|
| 91 |
+
std::string s3 = std::format("{}", err{}); // error: disabled formatter
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
— *end example*]
|
| 95 |
+
|