Skip to content

Commit 1550bdc

Browse files
committed
format std::reference_wrapper
1 parent 2a2f73f commit 1550bdc

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/fmt/std.h

+11
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>
@@ -699,4 +700,14 @@ template <typename T, typename Char> struct formatter<std::complex<T>, Char> {
699700
};
700701

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

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)