Difference between revisions of "cpp/named req/Formatter"
From cppreference.com
(Added LWG issue #3892 DR (part 2).) |
m (pc -> parse_ctx.) |
||
Line 21: | Line 21: | ||
{{dsc|{{c|t}}|a value of type convertible to (possibly const-qualified)<!-- LWG 3636 --> {{tt|Arg}}}} | {{dsc|{{c|t}}|a value of type convertible to (possibly const-qualified)<!-- LWG 3636 --> {{tt|Arg}}}} | ||
{{dsc|{{c|parse_ctx}}|an lvalue of type {{tt|ParseCtx}} satisfying all following conditions: | {{dsc|{{c|parse_ctx}}|an lvalue of type {{tt|ParseCtx}} satisfying all following conditions: | ||
− | * {{c| | + | * {{c|parse_ctx.begin()}} points to the beginning of the {{spar|format-spec}} of the replacement field being formatted in the [[cpp/utility/format/basic_format_string#Format specification|format string]]. |
− | * If {{spar|format-spec}} is not present or empty, then either {{c|1= | + | * If {{spar|format-spec}} is not present or empty, then either {{c|1=parse_ctx.begin() == parse_ctx.end()}} or {{c|1=*parse_ctx.begin() == '}'}}.}} |
{{dsc|{{c|fmt_ctx}}|an lvalue of type {{tt|FmtCtx}}}} | {{dsc|{{c|fmt_ctx}}|an lvalue of type {{tt|FmtCtx}}}} | ||
{{dsc end}} | {{dsc end}} | ||
Line 45: | Line 45: | ||
|As above, but does not modify {{c|arg}}. | |As above, but does not modify {{c|arg}}. | ||
|} | |} | ||
− | |||
===Defect reports=== | ===Defect reports=== |
Latest revision as of 22:19, 4 February 2024
Formatter is a type that abstracts formatting operations for a given formatting argument type and character type. Specializations of std::formatter provided by the standard library are required to meet the requirements of Formatter except as noted otherwise.
A Formatter is able to format both const and non-const arguments, typically by providing a format
member function that takes a const reference.
[edit] Requirements
A type satisfies Formatter if it satisfies BasicFormatter and given the following types and values, the expressions shown in the table below are valid and have the indicated semantics:
Type | Definition |
CharT
|
a character type |
Arg
|
a formatting argument type |
Formatter
|
a Formatter type for types Arg and CharT
|
OutputIt
|
a LegacyOutputIterator type |
ParseCtx
|
std::basic_format_parse_context<CharT> |
FmtCtx
|
std::basic_format_context<OutputIt, CharT> |
Value | Definition |
f | a value of type (possibly const-qualified) Formatter
|
arg | an lvalue of type Arg
|
t | a value of type convertible to (possibly const-qualified) Arg
|
parse_ctx | an lvalue of type ParseCtx satisfying all following conditions:
|
fmt_ctx | an lvalue of type FmtCtx
|
Expression | Return type | Semantics |
---|---|---|
f.format(t, fmt_ctx) | FmtCtx::iterator
|
|
f.format(arg, fmt_ctx) | FmtCtx::iterator
|
As above, but does not modify arg. |
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 3892 | C++20 | the value of pc.begin() was unclear if format-spec is not present | made clear |