28 Text processing library [text]
28.5 Formatting [format]
28.5.9 Tuple formatter [format.tuple]
For each of pair and tuple, the library provides the following formatter specialization where pair-or-tuple is the name of the template:
namespace std { template<class charT, formattable<charT>... Ts> struct formatter<pair-or-tuple<Ts...>, charT> { private: tuple<formatter<remove_cvref_t<Ts>, charT>...> underlying_; basic_string_view<charT> separator_ = STATICALLY-WIDEN<charT>(", "); basic_string_view<charT> opening-bracket_ = STATICALLY-WIDEN<charT>("("); basic_string_view<charT> closing-bracket_ = STATICALLY-WIDEN<charT>(")"); public: constexpr void set_separator(basic_string_view<charT> sep) noexcept; constexpr void set_brackets(basic_string_view<charT> opening, basic_string_view<charT> closing) noexcept; template<class ParseContext> constexpr typename ParseContext::iterator parse(ParseContext& ctx); template<class FormatContext> constexpr typename FormatContext::iterator format(see below& elems, FormatContext& ctx) const; }; template<class... Ts> constexpr bool enable_nonlocking_formatter_optimization<pair-or-tuple<Ts...>> = (enable_nonlocking_formatter_optimization<remove_cvref_t<Ts>> && ...); }
The parse member functions of these formatters interpret the format specification as a tuple-format-spec according to the following syntax:
tuple-format-spec :
tuple-fill-and-align width tuple-type
tuple-fill-and-align :
tuple-fill align
tuple-fill :
any character other than { or } or :
constexpr void set_separator(basic_string_view<charT> sep) noexcept;
Effects: Equivalent to: separator_ = sep;
constexpr void set_brackets(basic_string_view<charT> opening,
basic_string_view<charT> closing) noexcept;
Effects: Equivalent to: opening-bracket_ = opening; closing-bracket_ = closing;
template<class ParseContext>
constexpr typename ParseContext::iterator
parse(ParseContext& ctx);
Effects: Parses the format specifiers as a tuple-format-spec and stores the parsed specifiers in *this.
The values of opening-bracket_, closing-bracket_, and separator_ are modified if and only if required by the tuple-type, if present.
For each element e in underlying_, calls e.parse(ctx) to parse an empty format-spec and, if e.set_debug_format() is a valid expression, calls e.set_debug_format().
Returns: An iterator past the end of the tuple-format-spec.
template<class FormatContext>
typename FormatContext::iterator
format(see below& elems, FormatContext& ctx) const;
The type of elems is:
If (formattable<const Ts, charT> && ...) is true, const pair-or-tuple<Ts...>&.
Otherwise pair-or-tuple<Ts...>&.
Effects: Writes the following into ctx.out(), adjusted according to the tuple-format-spec:
- opening-bracket_,
- for each index I in the [0, sizeof...(Ts)):
- if I != 0, separator_,
- the result of writing get<I>(elems) via get<I>(underlying_), and
- closing-bracket_.
Returns: An iterator past the end of the output range.