22 General utilities library [utilities]

22.14 Formatting [format]

22.14.5 Formatting functions [format.functions]

In the description of the functions, operator + is used for some of the iterator categories for which it does not have to be defined.
In these cases the semantics of a + n are the same as in [algorithms.requirements].
template<class... Args> string format(format_string<Args...> fmt, Args&&... args);
Effects: Equivalent to: return vformat(fmt.str, make_format_args(args...));
template<class... Args> wstring format(wformat_string<Args...> fmt, Args&&... args);
Effects: Equivalent to: return vformat(fmt.str, make_wformat_args(args...));
template<class... Args> string format(const locale& loc, format_string<Args...> fmt, Args&&... args);
Effects: Equivalent to: return vformat(loc, fmt.str, make_format_args(args...));
template<class... Args> wstring format(const locale& loc, wformat_string<Args...> fmt, Args&&... args);
Effects: Equivalent to: return vformat(loc, fmt.str, make_wformat_args(args...));
string vformat(string_view fmt, format_args args); wstring vformat(wstring_view fmt, wformat_args args); string vformat(const locale& loc, string_view fmt, format_args args); wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
Returns: A string object holding the character representation of formatting arguments provided by args formatted according to specifications given in fmt.
If present, loc is used for locale-specific formatting.
Throws: As specified in [format.err.report].
template<class Out, class... Args> Out format_to(Out out, format_string<Args...> fmt, Args&&... args);
Effects: Equivalent to: return vformat_to(std::move(out), fmt.str, make_format_args(args...));
template<class Out, class... Args> Out format_to(Out out, wformat_string<Args...> fmt, Args&&... args);
Effects: Equivalent to: return vformat_to(std::move(out), fmt.str, make_wformat_args(args...));
template<class Out, class... Args> Out format_to(Out out, const locale& loc, format_string<Args...> fmt, Args&&... args);
Effects: Equivalent to: return vformat_to(std::move(out), loc, fmt.str, make_format_args(args...));
template<class Out, class... Args> Out format_to(Out out, const locale& loc, wformat_string<Args...> fmt, Args&&... args);
Effects: Equivalent to: return vformat_to(std::move(out), loc, fmt.str, make_wformat_args(args...));
template<class Out> Out vformat_to(Out out, string_view fmt, format_args args); template<class Out> Out vformat_to(Out out, wstring_view fmt, wformat_args args); template<class Out> Out vformat_to(Out out, const locale& loc, string_view fmt, format_args args); template<class Out> Out vformat_to(Out out, const locale& loc, wstring_view fmt, wformat_args args);
Let charT be decltype(fmt)​::​value_type.
Constraints: Out satisfies output_iterator<const charT&>.
Preconditions: Out models output_iterator<const charT&>.
Effects: Places the character representation of formatting the arguments provided by args, formatted according to the specifications given in fmt, into the range [out, out + N), where N is the number of characters in that character representation.
If present, loc is used for locale-specific formatting.
Returns: out + N.
Throws: As specified in [format.err.report].
template<class Out, class... Args> format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, format_string<Args...> fmt, Args&&... args); template<class Out, class... Args> format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, wformat_string<Args...> fmt, Args&&... args); template<class Out, class... Args> format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, const locale& loc, format_string<Args...> fmt, Args&&... args); template<class Out, class... Args> format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, const locale& loc, wformat_string<Args...> fmt, Args&&... args);
Let
  • charT be decltype(fmt.str)​::​value_type,
  • N be formatted_size(fmt, args...) for the functions without a loc parameter and formatted_size(loc, fmt, args...) for the functions with a loc parameter, and
  • M be clamp(n, 0, N).
Constraints: Out satisfies output_iterator<const charT&>.
Preconditions: Out models output_iterator<const charT&>, and formatter<>, charT> meets the BasicFormatter requirements ([formatter.requirements]) for each in Args.
Effects: Places the first M characters of the character representation of formatting the arguments provided by args, formatted according to the specifications given in fmt, into the range [out, out + M).
If present, loc is used for locale-specific formatting.
Returns: {out + M, N}.
Throws: As specified in [format.err.report].
template<class... Args> size_t formatted_size(format_string<Args...> fmt, Args&&... args); template<class... Args> size_t formatted_size(wformat_string<Args...> fmt, Args&&... args); template<class... Args> size_t formatted_size(const locale& loc, format_string<Args...> fmt, Args&&... args); template<class... Args> size_t formatted_size(const locale& loc, wformat_string<Args...> fmt, Args&&... args);
Let charT be decltype(fmt.str)​::​value_type.
Preconditions: formatter<>, charT> meets the BasicFormatter requirements ([formatter.requirements]) for each in Args.
Returns: The number of characters in the character representation of formatting arguments args formatted according to specifications given in fmt.
If present, loc is used for locale-specific formatting.
Throws: As specified in [format.err.report].