mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 02:13:40 +00:00
Use fmt::formatter specialization for std::reference_wrapper to avoid undefined behavior (#4164)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
parent
ed8f8be70d
commit
1f87b1c58d
@ -692,15 +692,17 @@ template <typename T, typename Char> struct formatter<std::complex<T>, Char> {
|
||||
}
|
||||
};
|
||||
|
||||
FMT_EXPORT
|
||||
template <typename T, typename Char>
|
||||
struct formatter<std::reference_wrapper<T>, Char,
|
||||
enable_if_t<is_formattable<remove_cvref_t<T>, Char>::value>>
|
||||
: formatter<remove_cvref_t<T>, Char> {
|
||||
template <typename FormatContext>
|
||||
auto format(std::reference_wrapper<T> ref, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return formatter<remove_cvref_t<T>, Char>::format(ref.get(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
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_
|
||||
|
Loading…
Reference in New Issue
Block a user