diff --git a/include/fmt/core.h b/include/fmt/core.h index 34cd7b3c..9f910b0b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1306,10 +1306,12 @@ std::basic_string vformat( basic_format_args::type> args); } // namespace internal +#define FMT_CHAR(Str) typename internal::format_string_traits::char_type + +template format_context::iterator vformat_to( - internal::buffer &buf, string_view format_str, format_args args); -wformat_context::iterator vformat_to( - internal::wbuffer &buf, wstring_view format_str, wformat_args args); + internal::basic_buffer &buf, const String &format_str, + basic_format_args > args); template struct is_contiguous : std::false_type {}; @@ -1359,8 +1361,6 @@ inline typename std::enable_if< make_format_args(args...)); } -#define FMT_CHAR(Str) typename internal::format_string_traits::char_type - template inline std::basic_string vformat( const String &format_str, diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index d74d4797..432b38b9 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -840,7 +840,7 @@ FMT_FUNC void report_windows_error( FMT_FUNC void vprint(std::FILE *f, string_view format_str, format_args args) { memory_buffer buffer; - vformat_to(buffer, format_str, args); + vformat_to(buffer, format_str, basic_format_args::type>(args)); std::fwrite(buffer.data(), 1, buffer.size(), f); } diff --git a/include/fmt/format.h b/include/fmt/format.h index b29eedbf..5e47b346 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3441,10 +3441,13 @@ std::basic_string to_string(const basic_memory_buffer &buf) { return std::basic_string(buf.data(), buf.size()); } -inline format_context::iterator vformat_to( - internal::buffer &buf, string_view format_str, format_args args) { - typedef back_insert_range range; - return vformat_to>(buf, format_str, args); +template +inline typename buffer_context::type::iterator vformat_to( + internal::basic_buffer &buf, const String &format_str, + basic_format_args::type> args) { + typedef back_insert_range > range; + return vformat_to>( + buf, basic_string_view(format_str), args); } inline wformat_context::iterator vformat_to( @@ -3477,17 +3480,11 @@ struct format_args_t { typename format_context_t::type> type; }; -template -inline OutputIt vformat_to(OutputIt out, string_view format_str, - typename format_args_t::type args) { - typedef output_range range; - return vformat_to>(range(out), format_str, args); -} -template +template inline OutputIt vformat_to( - OutputIt out, wstring_view format_str, - typename format_args_t::type args) { - typedef output_range range; + OutputIt out, const String &format_str, + typename format_args_t::type args) { + typedef output_range range; return vformat_to>(range(out), format_str, args); } @@ -3503,14 +3500,14 @@ inline OutputIt vformat_to( \endrst */ template -inline typename std::enable_if::value, OutputIt>::type - format_to(OutputIt out, const String &format_str, - const Args &... args) { +inline typename std::enable_if< + internal::is_format_string::value, OutputIt>::type + format_to(OutputIt out, const String &format_str, const Args &... args) { internal::check_format_string(format_str); - typedef typename format_context_t::type context_t; - format_arg_store as{args...}; + typedef typename format_context_t::type context; + format_arg_store as{args...}; return vformat_to(out, basic_string_view< FMT_CHAR(String) >(format_str), - basic_format_args(as)); + basic_format_args(as)); } template diff --git a/test/format-test.cc b/test/format-test.cc index 7e06e500..3ceeebbb 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1836,7 +1836,7 @@ TEST(StrTest, Convert) { EXPECT_EQ("2012-12-9", s); } -static std::string vformat_message(int id, const char *format, fmt::format_args args) { +std::string vformat_message(int id, const char *format, fmt::format_args args) { fmt::memory_buffer buffer; format_to(buffer, "[{}] ", id); vformat_to(buffer, format, args);