[format.functions] (original) (raw)

28 Text processing library [text]

28.5 Formatting [format]

28.5.5 Formatting functions [format.functions]

A call to any of the functions defined in this subclause is a constant subexpression only if each of the used formatter specializations is a constexpr-enabled specialization ([format.formatter.spec]).

In the description of the functions, operator + is used for some of the iterator categories for which it does not have to be defined.

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.

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.

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.

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

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.

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.

Returns: The number of characters in the character representation of formatting arguments argsformatted according to specifications given in fmt.

If present, loc is used for locale-specific formatting.