mirror of
https://github.com/fmtlib/fmt.git
synced 2026-02-05 17:30:06 +08:00
Improve compatibility with std::format
This commit is contained in:
parent
76d480c6fd
commit
f3d510c10c
@ -231,6 +231,14 @@ FMT_PRAGMA_GCC(optimize("Og"))
|
||||
#endif
|
||||
FMT_PRAGMA_CLANG(diagnostic push)
|
||||
|
||||
#ifdef FMT_DEPRECATED
|
||||
// Use the provided definition.
|
||||
#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
|
||||
# define FMT_DEPRECATED [[deprecated]]
|
||||
#else
|
||||
# define FMT_DEPRECATED /* deprecated */
|
||||
#endif
|
||||
|
||||
#ifdef FMT_ALWAYS_INLINE
|
||||
// Use the provided definition.
|
||||
#elif FMT_GCC_VERSION || FMT_CLANG_VERSION
|
||||
@ -2656,8 +2664,7 @@ template <typename... T> struct fstring {
|
||||
}
|
||||
fstring(runtime_format_string<> fmt) : str(fmt.str) {}
|
||||
|
||||
// Returning by reference generates better code in debug mode.
|
||||
FMT_ALWAYS_INLINE operator const string_view&() const { return str; }
|
||||
FMT_DEPRECATED operator const string_view&() const { return str; }
|
||||
auto get() const -> string_view { return str; }
|
||||
};
|
||||
|
||||
|
||||
@ -121,14 +121,6 @@
|
||||
# define FMT_NOINLINE
|
||||
#endif
|
||||
|
||||
#ifdef FMT_DEPRECATED
|
||||
// Use the provided definition.
|
||||
#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
|
||||
# define FMT_DEPRECATED [[deprecated]]
|
||||
#else
|
||||
# define FMT_DEPRECATED /* deprecated */
|
||||
#endif
|
||||
|
||||
// Detect constexpr std::string.
|
||||
#if !FMT_USE_CONSTEVAL
|
||||
# define FMT_USE_CONSTEXPR_STRING 0
|
||||
|
||||
@ -109,7 +109,7 @@ template <typename Char, typename... T> struct basic_fstring {
|
||||
}
|
||||
basic_fstring(runtime_format_string<Char> fmt) : str_(fmt.str) {}
|
||||
|
||||
operator basic_string_view<Char>() const { return str_; }
|
||||
FMT_DEPRECATED operator basic_string_view<Char>() const { return str_; }
|
||||
auto get() const -> basic_string_view<Char> { return str_; }
|
||||
};
|
||||
|
||||
@ -172,14 +172,13 @@ auto vformat(basic_string_view<Char> fmt,
|
||||
|
||||
template <typename... T>
|
||||
auto format(wformat_string<T...> fmt, T&&... args) -> std::wstring {
|
||||
return vformat(fmt::wstring_view(fmt), fmt::make_wformat_args(args...));
|
||||
return vformat(fmt.get(), fmt::make_wformat_args(args...));
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename... T>
|
||||
auto format_to(OutputIt out, wformat_string<T...> fmt, T&&... args)
|
||||
-> OutputIt {
|
||||
return vformat_to(out, fmt::wstring_view(fmt),
|
||||
fmt::make_wformat_args(args...));
|
||||
return vformat_to(out, fmt.get(), fmt::make_wformat_args(args...));
|
||||
}
|
||||
|
||||
// Pass char_t as a default template parameter instead of using
|
||||
@ -301,11 +300,11 @@ inline void vprint(wstring_view fmt, wformat_args args) {
|
||||
|
||||
template <typename... T>
|
||||
void print(std::FILE* f, wformat_string<T...> fmt, T&&... args) {
|
||||
return vprint(f, wstring_view(fmt), fmt::make_wformat_args(args...));
|
||||
return vprint(f, fmt.get(), fmt::make_wformat_args(args...));
|
||||
}
|
||||
|
||||
template <typename... T> void print(wformat_string<T...> fmt, T&&... args) {
|
||||
return vprint(wstring_view(fmt), fmt::make_wformat_args(args...));
|
||||
return vprint(fmt.get(), fmt::make_wformat_args(args...));
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
@ -327,7 +326,7 @@ inline auto vformat(text_style ts, wstring_view fmt, wformat_args args)
|
||||
template <typename... T>
|
||||
inline auto format(text_style ts, wformat_string<T...> fmt, T&&... args)
|
||||
-> std::wstring {
|
||||
return fmt::vformat(ts, fmt, fmt::make_wformat_args(args...));
|
||||
return fmt::vformat(ts, fmt.get(), fmt::make_wformat_args(args...));
|
||||
}
|
||||
|
||||
inline void vprint(std::wostream& os, wstring_view fmt, wformat_args args) {
|
||||
@ -338,7 +337,8 @@ inline void vprint(std::wostream& os, wstring_view fmt, wformat_args args) {
|
||||
|
||||
template <typename... T>
|
||||
void print(std::wostream& os, wformat_string<T...> fmt, T&&... args) {
|
||||
vprint(os, fmt, fmt::make_format_args<buffered_context<wchar_t>>(args...));
|
||||
vprint(os, fmt.get(),
|
||||
fmt::make_format_args<buffered_context<wchar_t>>(args...));
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user