From 8d545d7d6b7d45ec362309efbaf6c0549ec1bbba Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 28 Aug 2020 03:28:50 -0700 Subject: [PATCH] Backport fmt PR #1829 Summary: Backport https://github.com/fmtlib/fmt/pull/1829 to make sure that `fmt::to_string` supports streamable types. Reviewed By: h-friederich Differential Revision: D23387021 fbshipit-source-id: f538525a6fe2a296b508164f19a8bc0704183666 --- deps/fmt/include/fmt/format.h | 9 +++++++-- deps/fmt/test/ostream-test.cc | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/deps/fmt/include/fmt/format.h b/deps/fmt/include/fmt/format.h index 29221289..20ec7ee1 100644 --- a/deps/fmt/include/fmt/format.h +++ b/deps/fmt/include/fmt/format.h @@ -1810,8 +1810,13 @@ auto write(OutputIt out, const T& value) -> typename std::enable_if< mapped_type_constant>::value == type::custom_type, OutputIt>::type { - basic_format_context ctx(out, {}, {}); - return formatter().format(value, ctx); + using context_type = basic_format_context; + using formatter_type = + conditional_t::value, + typename context_type::template formatter_type, + fallback_formatter>; + context_type ctx(out, {}, {}); + return formatter_type().format(value, ctx); } // An argument visitor that formats the argument and writes it via the output diff --git a/deps/fmt/test/ostream-test.cc b/deps/fmt/test/ostream-test.cc index 1c87d46d..336c1ea5 100644 --- a/deps/fmt/test/ostream-test.cc +++ b/deps/fmt/test/ostream-test.cc @@ -307,3 +307,7 @@ TEST(OStreamTest, CopyFmt) { TEST(OStreamTest, CompileTimeString) { EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42)); } + +TEST(OStreamTest, ToString) { + EXPECT_EQ("ABC", fmt::to_string(fmt_test::ABC())); +}