C++ named requirements: BasicFormatter (since C++20)
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
C++ named requirements
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++17)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++17)
(C++20)
BasicFormatter
(C++20)
(C++20)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++14)
(C++14)
(C++11)
(C++11)
(C++17)
(C++14)
(C++20)
(C++20)
(C++23)
(C++23)
(C++23)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
BasicFormatter is a type that abstracts formatting operations for a given formatting argument type and character type. Specializations of std::formatter are required to meet the requirements of BasicFormatter.
A BasicFormatter is a Formatter if it is able to format both const and non-const arguments.
[edit] Requirements
A type satisfies BasicFormatter if it is semiregular, meaning it satisfies:
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
g
a value of type
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:
- parse_ctx.begin() points to the beginning of the format-spec of the replacement field being formatted in the format string.
- If format-spec is not present or empty, then either parse_ctx.begin() == parse_ctx.end() or *parse_ctx.begin() == '}'.
fmt_ctx
an lvalue of type
FmtCtx
Expression | Return type | Semantics |
---|---|---|
g.parse(parse_ctx) | ParseCtx::iterator
|
|
f.format(arg, fmt_ctx) | FmtCtx::iterator
|
|
- ↑ This allows formatters to emit meaningful error messages.
[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 |