Localization library | |||||||||||||||||||||||||
Regular expressions library(C++11) | |||||||||||||||||||||||||
Formatting library(C++20) | |||||||||||||||||||||||||
Null-terminated sequence utilities | |||||||||||||||||||||||||
Byte strings | |||||||||||||||||||||||||
Multibyte strings | |||||||||||||||||||||||||
Wide strings | |||||||||||||||||||||||||
Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Text encoding identifications | |||||||||||||||||||||||||
|
Standard format specification | ||||
Formatting functions | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
Format strings | ||||
(C++20)(C++20)(C++20) | ||||
(C++26) | ||||
Formatting concepts | ||||
(C++23) | ||||
Formatter | ||||
(C++20) | ||||
formatter<pair-or-tuple> (C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++20)(C++20)(C++20) | ||||
(C++20)(C++20)(C++20) | ||||
(C++23) | ||||
(C++23) | ||||
Formatting arguments | ||||
(C++20) | ||||
(C++20) | ||||
(C++20)(C++20)(C++20) | ||||
(C++20)(deprecated in C++26) | ||||
(C++20)(C++20) | ||||
Format error | ||||
(C++20) |
Defined in header <format> | ||
template<class CharT,std::formattable<CharT>...Ts> struct formatter</*pair-or-tuple*/<Ts...>, CharT>; | (since C++23) | |
The template specialization ofstd::formatter for thestd::pair andstd::tuple allows users to convert a pair or a tuple to its textual representation as a collection of elements usingformatting functions.
The exposition-only name/*pair-or-tuple*/ denotes either class templatestd::pair orstd::tuple.
This specialization meets theFormatter requirements if(std::formattable<const Ts, CharT>&& ...) istrue. It always meets theBasicFormatter requirements.
Contents |
The syntax oftuple-format-spec is:
tuple-fill-and-align (optional)width (optional)tuple-type (optional) | |||||||||
Thetuple-fill-and-align is interpreted the same way as afill-and-align except that thefill intuple-fill-and-align is any character other than{
,}
, or:
.
Thewidth is described instandard format width specification.
Thetuple-type changes the way a tuple is formatted, with certain options only valid with certain argument types.
The available tuple presentation types are:
m
: Indicates that both opening and closing brackets should be"" while the separator should be": ".m
is chosen as thetuple-type, the program is ill-formed unlesssizeof...(Ts)==2 istrue.n
: Indicates that separator, opening and closing brackets should be"".Member name | Definition |
underlying_ (private) | tuple of underlying formatters of typestd::tuple<std::formatter<std::remove_cvref_t<Ts>, CharT>...> (exposition-only member object*) |
separator_ (private) | a string representing the separator of the tuple formatted result (defaults to", ") (exposition-only member object*) |
opening-bracket_ (private) | a string representing the opening bracket of the tuple formatted result (defaults to"(") (exposition-only member object*) |
closing-bracket_ (private) | a string representing the closing bracket of the tuple formatted result (defaults to")") (exposition-only member object*) |
set_separator | sets a specified separator for the tuple formatted result (public member function) |
set_brackets | sets a specified opening and closing brackets for the tuple formatted result (public member function) |
parse | parses the format specifier as specified bytuple-format-spec (public member function) |
format | writes the tuple formatted output as specified bytuple-format-spec (public member function) |
constexprvoid set_separator(std::basic_string_view<CharT> sep)noexcept; | ||
Assignssep toseparator_
.
constexprvoid set_brackets(std::basic_string_view<CharT> opening, std::basic_string_view<CharT> closing)noexcept; | ||
Assignsopening andclosing toopening-bracket_
andclosing-bracket_
, respectively.
template<class ParseContext> constexprauto parse( ParseContext& ctx)-> ParseContext::iterator; | ||
Parses the format specifiers as atuple-format-spec and stores the parsed specifiers in the current object.
Iftuple-type or then
option is present, the values ofopening-bracket
,closing-bracket
, andseparator
are modified as required.
For each elemente inunderlying_
, callse.parse(ctx) to parse an emptyformat-spec and, ife.set_debug_format() is a valid expression, callse.set_debug_format().
Returns an iterator past the end of thetuple-format-spec.
template<class FormatContext> FormatContext::iterator | ||
/*maybe-const-pair-or-tuple*/ denotes:
Writes the following intoctx.out() as specified bytuple-format-spec, in order:
opening-bracket_
,[
0,
sizeof...(Ts))
:separator_
,underlying_
), andclosing-bracket_
.Returns an iterator past the end of the output range.
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++23 | the formatting of nested tuples was incorrect | corrected |
(C++20) | defines formatting rules for a given type (class template)[edit] |