diff --git a/include/fmt/format.h b/include/fmt/format.h index cc75f8eb..8c00066a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3480,9 +3480,9 @@ std::wstring to_wstring(const T &value) { return str; } -template -std::basic_string to_string(const basic_memory_buffer &buffer) { - return std::basic_string(buffer.data(), buffer.size()); +template +std::basic_string to_string(const basic_memory_buffer &buf) { + return std::basic_string(buf.data(), buf.size()); } inline format_context::iterator vformat_to( @@ -3497,15 +3497,17 @@ inline wformat_context::iterator vformat_to( return vformat_to>(buf, format_str, args); } -template +template inline format_context::iterator format_to( - memory_buffer &buf, string_view format_str, const Args & ... args) { + basic_memory_buffer &buf, string_view format_str, + const Args & ... args) { return vformat_to(buf, format_str, make_format_args(args...)); } -template +template inline wformat_context::iterator format_to( - wmemory_buffer &buf, wstring_view format_str, const Args & ... args) { + basic_memory_buffer &buf, wstring_view format_str, + const Args & ... args) { return vformat_to(buf, format_str, make_format_args(args...)); } diff --git a/test/format-test.cc b/test/format-test.cc index fdbf3654..e2d62c30 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -233,6 +233,12 @@ TEST(FormatToTest, FormatToNonbackInsertIteratorWithSignAndNumericAlignment) { EXPECT_STREQ("+42", buffer); } +TEST(FormatToTest, FormatToMemoryBuffer) { + fmt::basic_memory_buffer buffer; + fmt::format_to(buffer, "{}", "foo"); + EXPECT_EQ("foo", to_string(buffer)); +} + TEST(FormatterTest, Escape) { EXPECT_EQ("{", format("{{")); EXPECT_EQ("before {", format("before {{"));