From e4ca37ccf6723bd041a3fc677614551e32bf1f12 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 25 Sep 2018 07:47:15 -0700 Subject: [PATCH] Parameterize format_to on string type (#880) --- include/fmt/format.h | 11 +++++++---- test/format-test.cc | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) 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);