format std::reference_wrapper

This commit is contained in:
Yedidya Feldblum
2024-09-16 13:37:19 -05:00
committed by Victor Zverovich
parent 4197727712
commit 07e70151d5
2 changed files with 16 additions and 0 deletions

View File

@ -17,6 +17,7 @@
# include <complex>
# include <cstdlib>
# include <exception>
# include <functional>
# include <memory>
# include <thread>
# include <type_traits>
@ -692,4 +693,14 @@ template <typename T, typename Char> struct formatter<std::complex<T>, Char> {
};
FMT_END_NAMESPACE
namespace std {
template <typename T>
constexpr auto format_as(std::reference_wrapper<T> ref) -> T& {
return ref.get();
}
} // namespace std
#endif // FMT_STD_H_

View File

@ -395,3 +395,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)));
}