diff --git a/include/format b/include/format index 167a5fba..633a731c 100644 --- a/include/format +++ b/include/format @@ -716,34 +716,36 @@ string vformat(string_view fmt, format_args args) { wstring vformat(wstring_view fmt, wformat_args args); -template) O, class... Args> - O format_to(O out, string_view fmt, const Args&... args) { - return vformat_to(out, fmt, {make_format_args>(args...)}); +template + Out format_to(Out out, string_view fmt, const Args&... args) { + using context = basic_format_context; + return vformat_to(out, fmt, {make_format_args(args...)}); } -template) O, class... Args> - O format_to(O out, wstring_view fmt, const Args&... args) { - return vformat_to(out, fmt, {make_format_args>(args...)}); +template + Out format_to(Out out, wstring_view fmt, const Args&... args) { + using context = basic_format_context; + return vformat_to(out, fmt, {make_format_args(args...)}); } -template) O> - O vformat_to(O out, string_view fmt, format_args_t args) { - typedef fmt::output_range range; - detail::format_handler, char, basic_format_context> +template + Out vformat_to(Out out, string_view fmt, format_args_t args) { + typedef fmt::output_range range; + detail::format_handler, char, basic_format_context> h(range(out), fmt, args, {}); fmt::internal::parse_format_string(fmt::to_string_view(fmt), h); return h.context.out(); } -template) O> - O vformat_to(O out, wstring_view fmt, format_args_t args); +template + Out vformat_to(Out out, wstring_view fmt, format_args_t args); -template) O, class... Args> - format_to_n_result format_to_n(O out, iter_difference_t n, - string_view fmt, const Args&... args); -template) O, class... Args> - format_to_n_result format_to_n(O out, iter_difference_t n, - wstring_view fmt, const Args&... args); +template + format_to_n_result format_to_n(Out out, iter_difference_t n, + string_view fmt, const Args&... args); +template + format_to_n_result format_to_n(Out out, iter_difference_t n, + wstring_view fmt, const Args&... args); template size_t formatted_size(string_view fmt, const Args&... args); @@ -764,11 +766,11 @@ template struct formatter : detail::formatter, charT> {}; template - struct formatter, charT> + struct formatter, charT> : detail::formatter, charT> {}; template - struct formatter, charT> + struct formatter, charT> : detail::formatter, charT> {}; template <> struct formatter : detail::formatter {}; @@ -845,4 +847,50 @@ template <> struct formatter : detail::formatter6}", 'x'); // s3 == "*****x" + string s4 = format("{:*^6}", 'x'); // s4 == "**x***" + string s5 = format("{:=6}", 'x'); // Error: '=' with charT and no integer presentation type + string s6 = format("{:6d}", c); // s6 == " 120" + string s7 = format("{:=+06d}", c); // s7 == "+00120" + string s8 = format("{:0=#6x}", 0xa); // s8 == "0x000a" + string s9 = format("{:6}", true); // s9 == "true " +} + +inline void test3() { + using namespace std; + double inf = numeric_limits::infinity(); + double nan = numeric_limits::quiet_NaN(); + string s0 = format("{0:} {0:+} {0:-} {0: }", 1); // s0 == "1 +1 1 1" + string s1 = format("{0:} {0:+} {0:-} {0: }", -1); // s1 == "-1 -1 -1 -1" + string s2 = format("{0:} {0:+} {0:-} {0: }", inf); // s2 == "inf +inf inf inf" + string s3 = format("{0:} {0:+} {0:-} {0: }", nan); // s3 == "nan +nan nan nan" +} + +inline void test4() { + using namespace std; + string s0 = format("{}", 42); // s0 == "42" + string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // s1 == "101010 42 52 2a" + string s2 = format("{0:#x} {0:#X}", 42); // s2 == "0x2a 0X2A" + string s3 = format("{:n}", 1234); // s3 == "1,234" (depends on the locale) +} + #endif // FMT_FORMAT_