Skip to content

Commit 07e7015

Browse files
yfeldblumvitaut
authored andcommitted
format std::reference_wrapper
1 parent 4197727 commit 07e7015

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>
@@ -692,4 +693,14 @@ template <typename T, typename Char> struct formatter<std::complex<T>, Char> {
692693
};
693694

694695
FMT_END_NAMESPACE
696+
697+
namespace std {
698+
699+
template <typename T>
700+
constexpr auto format_as(std::reference_wrapper<T> ref) -> T& {
701+
return ref.get();
702+
}
703+
704+
} // namespace std
705+
695706
#endif // FMT_STD_H_

test/std-test.cc

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

0 commit comments

Comments
 (0)