From 1550bdc78c06f5902c45c0c73eaec7d367a110ba Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Mon, 16 Sep 2024 13:37:19 -0500 Subject: [PATCH] format std::reference_wrapper --- include/fmt/std.h | 11 +++++++++++ test/std-test.cc | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/include/fmt/std.h b/include/fmt/std.h index 1e69b8b23fe2..403c10af1f69 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -17,6 +17,7 @@ # include # include # include +# include # include # include # include @@ -699,4 +700,14 @@ template struct formatter, Char> { }; FMT_END_NAMESPACE + +namespace std { + +template +constexpr auto format_as(std::reference_wrapper ref) -> T& { + return ref.get(); +} + +} // namespace std + #endif // FMT_STD_H_ diff --git a/test/std-test.cc b/test/std-test.cc index 424441816501..722fa73760d2 100644 --- a/test/std-test.cc +++ b/test/std-test.cc @@ -393,3 +393,8 @@ TEST(std_test, format_shared_ptr) { EXPECT_EQ(fmt::format("{}", fmt::ptr(sp.get())), fmt::format("{}", fmt::ptr(sp))); } + +TEST(std_test, format_reference_wrapper) { + int num = 35; + EXPECT_EQ("35", fmt::to_string(std::cref(num))); +}