From 2b6a786e3507a9a5a856cb58c09413acf212c7ed Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 20 Oct 2024 09:08:24 -0700 Subject: [PATCH] Use standard context in print --- include/fmt/compile.h | 6 +++--- test/compile-test.cc | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 29226350..b4a1c14b 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -524,9 +524,9 @@ FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args) template ::value)> void print(std::FILE* f, const S& fmt, const Args&... args) { - memory_buffer buffer; - fmt::format_to(std::back_inserter(buffer), fmt, args...); - detail::print(f, {buffer.data(), buffer.size()}); + auto buf = memory_buffer(); + fmt::format_to(appender(buf), fmt, args...); + detail::print(f, {buf.data(), buf.size()}); } template struct formatter : formatter { + auto format(std_context_test, format_context& ctx) const + -> decltype(ctx.out()) { + return ctx.out(); + } +}; +FMT_END_NAMESPACE + TEST(compile_test, print) { EXPECT_WRITE(stdout, fmt::print(FMT_COMPILE("Don't {}!"), "panic"), "Don't panic!"); EXPECT_WRITE(stderr, fmt::print(stderr, FMT_COMPILE("Don't {}!"), "panic"), "Don't panic!"); + fmt::print(FMT_COMPILE("{}"), std_context_test()); } #endif