Skip to content

Commit 8fac8c2

Browse files
committed
format std::reference_wrapper
1 parent 2a2f73f commit 8fac8c2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

include/fmt/std.h

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# include <complex>
1818
# include <cstdlib>
1919
# include <exception>
20+
# include <functional>
2021
# include <memory>
2122
# include <thread>
2223
# include <type_traits>
@@ -700,3 +701,12 @@ template <typename T, typename Char> struct formatter<std::complex<T>, Char> {
700701

701702
FMT_END_NAMESPACE
702703
#endif // FMT_STD_H_
704+
705+
namespace std {
706+
707+
template <typename T>
708+
constexpr auto format_as(std::reference_wrapper<T> ref) -> T& {
709+
return ref.get();
710+
}
711+
712+
} // namespace std

test/std-test.cc

+5
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,8 @@ TEST(std_test, format_shared_ptr) {
393393
EXPECT_EQ(fmt::format("{}", fmt::ptr(sp.get())),
394394
fmt::format("{}", fmt::ptr(sp)));
395395
}
396+
397+
TEST(std_test, format_reference_wrapper) {
398+
int num = 35;
399+
EXPECT_EQ("35", fmt::to_string(std::cref(num)));
400+
}

0 commit comments

Comments
 (0)