diff --git a/include/fmt/format.h b/include/fmt/format.h index 9f2a1d2f..4ba7a4da 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3501,11 +3501,14 @@ inline OutputIt vformat_to( fmt::format_to(std::back_inserter(out), "{}", 42); \endrst */ -template -inline OutputIt format_to(OutputIt out, string_view format_str, +template +inline OutputIt format_to(OutputIt out, const String &format_str, const Args &... args) { - return vformat_to(out, format_str, - make_format_args::type>(args...)); + internal::check_format_string(format_str); + typedef typename format_context_t::type context_t; + format_arg_store as{args...}; + return vformat_to(out, basic_string_view< FMT_CHAR(String) >(format_str), + basic_format_args(as)); } template diff --git a/test/format-test.cc b/test/format-test.cc index 31a76c3a..8dbb4dfb 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -682,6 +682,12 @@ TEST(FormatToTest, Format) { EXPECT_EQ("part1part2", s); } +TEST(FormatToTest, WideString) { + std::vector buf; + fmt::format_to(std::back_inserter(buf), L"{}{}", 42, L'\0'); + EXPECT_STREQ(buf.data(), L"42"); +} + TEST(FormatToTest, FormatToNonbackInsertIteratorWithSignAndNumericAlignment) { char buffer[16] = {}; fmt::format_to(buffer, "{: =+}", 42.0);