From 9d16b46fdb42a9b6134e839221053a8402627a18 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sun, 3 Jul 2022 18:42:08 +0500 Subject: [PATCH] Add xchar support for fmt::streamed(). Signed-off-by: Vladislav Shchapov --- include/fmt/ostream.h | 9 +++++---- test/xchar-test.cc | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 394d947c563c..ced05f75baf2 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -142,12 +142,13 @@ struct basic_ostream_formatter : formatter, Char> { using ostream_formatter = basic_ostream_formatter; -template -struct formatter> : ostream_formatter { +template +struct formatter, Char> + : basic_ostream_formatter { template auto format(detail::streamed_view view, - basic_format_context& ctx) const -> OutputIt { - return ostream_formatter::format(view.value, ctx); + basic_format_context& ctx) const -> OutputIt { + return basic_ostream_formatter::format(view.value, ctx); } }; diff --git a/test/xchar-test.cc b/test/xchar-test.cc index ea8bc85ab337..290f5ffa7877 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -229,6 +229,19 @@ TEST(xchar_test, enum) { EXPECT_EQ(L"0", fmt::format(L"{}", unstreamable_enum())); } +struct streamable_and_unformattable {}; + +auto operator<<(std::wostream& os, streamable_and_unformattable) + -> std::wostream& { + return os << L"foo"; +} + +TEST(xchar_test, streamed) { + EXPECT_FALSE(fmt::is_formattable()); + EXPECT_EQ(fmt::format(L"{}", fmt::streamed(streamable_and_unformattable())), + L"foo"); +} + TEST(xchar_test, sign_not_truncated) { wchar_t format_str[] = { L'{', L':',