Init
This commit is contained in:
26
cppdraft/format/formatter/locking.md
Normal file
26
cppdraft/format/formatter/locking.md
Normal file
@@ -0,0 +1,26 @@
|
||||
[format.formatter.locking]
|
||||
|
||||
# 28 Text processing library [[text]](./#text)
|
||||
|
||||
## 28.5 Formatting [[format]](format#formatter.locking)
|
||||
|
||||
### 28.5.6 Formatter [[format.formatter]](format.formatter#locking)
|
||||
|
||||
#### 28.5.6.2 Formatter locking [format.formatter.locking]
|
||||
|
||||
[ð](#lib:enable_nonlocking_formatter_optimization)
|
||||
|
||||
`template<class T>
|
||||
constexpr bool enable_nonlocking_formatter_optimization = false;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7086)
|
||||
|
||||
*Remarks*: Pursuant to [[namespace.std]](namespace.std "16.4.5.2.1 Namespace std"),
|
||||
users may specialize enable_nonlocking_formatter_optimization for
|
||||
cv-unqualified program-defined types[.](#1.sentence-1)
|
||||
|
||||
Such specializations shall be usable in constant expressions ([[expr.const]](expr.const "7.7 Constant expressions"))
|
||||
and have type const bool[.](#1.sentence-2)
|
||||
140
cppdraft/format/formatter/spec.md
Normal file
140
cppdraft/format/formatter/spec.md
Normal file
@@ -0,0 +1,140 @@
|
||||
[format.formatter.spec]
|
||||
|
||||
# 28 Text processing library [[text]](./#text)
|
||||
|
||||
## 28.5 Formatting [[format]](format#formatter.spec)
|
||||
|
||||
### 28.5.6 Formatter [[format.formatter]](format.formatter#spec)
|
||||
|
||||
#### 28.5.6.4 Formatter specializations [format.formatter.spec]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7130)
|
||||
|
||||
The functions defined in [[format.functions]](format.functions "28.5.5 Formatting functions") use
|
||||
specializations of the class template formatter to format
|
||||
individual arguments[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7136)
|
||||
|
||||
Let charT be either char or wchar_t[.](#2.sentence-1)
|
||||
|
||||
Each specialization of formatter is either enabled or disabled,
|
||||
as described below[.](#2.sentence-2)
|
||||
|
||||
A [*debug-enabled*](#def:debug-enabled "28.5.6.4 Formatter specializations [format.formatter.spec]") specialization of formatter additionally provides
|
||||
a public, constexpr, non-static member function set_debug_format() which modifies the state of the formatter to be as if
|
||||
the type of the *std-format-spec* parsed by the last call to parse were ?[.](#2.sentence-3)
|
||||
|
||||
Each header that declares the template formatter provides the following enabled specializations:
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
The debug-enabled specializationstemplate<> struct formatter<char, char>;template<> struct formatter<char, wchar_t>;template<> struct formatter<wchar_t, wchar_t>;
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
For each charT,
|
||||
the debug-enabled string type specializationstemplate<> struct formatter<charT*, charT>;template<> struct formatter<const charT*, charT>;template<size_t N> struct formatter<charT[N], charT>;template<class traits, class Allocator>struct formatter<basic_string<charT, traits, Allocator>, charT>;template<class traits>struct formatter<basic_string_view<charT, traits>, charT>;
|
||||
|
||||
- [(2.3)](#2.3)
|
||||
|
||||
For each charT,
|
||||
for each cv-unqualified arithmetic type ArithmeticT other thanchar,wchar_t,char8_t,char16_t, orchar32_t,
|
||||
a specializationtemplate<> struct formatter<ArithmeticT, charT>;
|
||||
|
||||
- [(2.4)](#2.4)
|
||||
|
||||
For each charT,
|
||||
the pointer type specializationstemplate<> struct formatter<nullptr_t, charT>;template<> struct formatter<void*, charT>;template<> struct formatter<const void*, charT>;
|
||||
|
||||
The parse member functions of these formatters
|
||||
interpret the format specification
|
||||
as a *std-format-spec* as described in [[format.string.std]](format.string.std "28.5.2.2 Standard format specifiers")[.](#2.sentence-4)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7204)
|
||||
|
||||
Unless specified otherwise, for each type T for which
|
||||
a formatter specialization is provided by the library,
|
||||
each of the headers provides the following specialization:template<> inline constexpr bool enable_nonlocking_formatter_optimization<T> = true;
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Specializations such as formatter<wchar_t, char> that would require implicit
|
||||
multibyte / wide string or character conversion are disabled[.](#3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7217)
|
||||
|
||||
The header <format> provides
|
||||
the following disabled specializations:
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
The string type specializationstemplate<> struct formatter<char*, wchar_t>;template<> struct formatter<const char*, wchar_t>;template<size_t N> struct formatter<char[N], wchar_t>;template<class traits, class Allocator>struct formatter<basic_string<char, traits, Allocator>, wchar_t>;template<class traits>struct formatter<basic_string_view<char, traits>, wchar_t>;
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7234)
|
||||
|
||||
For any types T and charT for which
|
||||
neither the library nor the user provides
|
||||
an explicit or partial specialization of
|
||||
the class template formatter,formatter<T, charT> is disabled[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7241)
|
||||
|
||||
If the library provides an explicit or partial specialization offormatter<T, charT>, that specialization is enabled
|
||||
and meets the *Formatter* requirements
|
||||
except as noted otherwise[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7247)
|
||||
|
||||
If F is a disabled specialization of formatter, these
|
||||
values are false:
|
||||
|
||||
- [(7.1)](#7.1)
|
||||
|
||||
is_default_constructible_v<F>,
|
||||
|
||||
- [(7.2)](#7.2)
|
||||
|
||||
is_copy_constructible_v<F>,
|
||||
|
||||
- [(7.3)](#7.3)
|
||||
|
||||
is_move_constructible_v<F>,
|
||||
|
||||
- [(7.4)](#7.4)
|
||||
|
||||
is_copy_assignable_v<F>, and
|
||||
|
||||
- [(7.5)](#7.5)
|
||||
|
||||
is_move_assignable_v<F>[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7258)
|
||||
|
||||
An enabled specialization formatter<T, charT> meets the*BasicFormatter* requirements ([[formatter.requirements]](formatter.requirements "28.5.6.1 Formatter requirements"))[.](#8.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*: #include <format>#include <string>enum color { red, green, blue };const char* color_names[] = { "red", "green", "blue" };
|
||||
|
||||
template<> struct std::formatter<color> : std::formatter<const char*> {auto format(color c, format_context& ctx) const {return formatter<const char*>::format(color_names[c], ctx); }};
|
||||
|
||||
struct err {};
|
||||
|
||||
std::string s0 = std::format("{}", 42); // OK, library-provided formatter std::string s1 = std::format("{}", L"foo"); // error: disabled formatter std::string s2 = std::format("{}", red); // OK, user-provided formatter std::string s3 = std::format("{}", err{}); // error: disabled formatter â *end example*]
|
||||
Reference in New Issue
Block a user