Skip to content

Commit

Permalink
Backport fmt PR #1829
Browse files Browse the repository at this point in the history
Summary: Backport fmtlib/fmt#1829 to make sure that `fmt::to_string` supports streamable types.

Reviewed By: h-friederich

Differential Revision: D23387021

fbshipit-source-id: f538525a6fe2a296b508164f19a8bc0704183666
  • Loading branch information
vitaut authored and facebook-github-bot committed Aug 28, 2020
1 parent cf90409 commit 8d545d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions deps/fmt/include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1810,8 +1810,13 @@ auto write(OutputIt out, const T& value) -> typename std::enable_if<
mapped_type_constant<T, basic_format_context<OutputIt, Char>>::value ==
type::custom_type,
OutputIt>::type {
basic_format_context<OutputIt, Char> ctx(out, {}, {});
return formatter<T>().format(value, ctx);
using context_type = basic_format_context<OutputIt, Char>;
using formatter_type =
conditional_t<has_formatter<T, context_type>::value,
typename context_type::template formatter_type<T>,
fallback_formatter<T, Char>>;
context_type ctx(out, {}, {});
return formatter_type().format(value, ctx);
}

// An argument visitor that formats the argument and writes it via the output
Expand Down
4 changes: 4 additions & 0 deletions deps/fmt/test/ostream-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

0 comments on commit 8d545d7

Please sign in to comment.