mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-29 18:27:40 +02:00
format std::reference_wrapper
This commit is contained in:
committed by
Victor Zverovich
parent
4197727712
commit
07e70151d5
@ -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_
|
||||
|
@ -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)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user