Skip to content

Commit f3d510c

Browse files
committed
Improve compatibility with std::format
1 parent 76d480c commit f3d510c

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

include/fmt/base.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ FMT_PRAGMA_GCC(optimize("Og"))
231231
#endif
232232
FMT_PRAGMA_CLANG(diagnostic push)
233233

234+
#ifdef FMT_DEPRECATED
235+
// Use the provided definition.
236+
#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
237+
# define FMT_DEPRECATED [[deprecated]]
238+
#else
239+
# define FMT_DEPRECATED /* deprecated */
240+
#endif
241+
234242
#ifdef FMT_ALWAYS_INLINE
235243
// Use the provided definition.
236244
#elif FMT_GCC_VERSION || FMT_CLANG_VERSION
@@ -2656,8 +2664,7 @@ template <typename... T> struct fstring {
26562664
}
26572665
fstring(runtime_format_string<> fmt) : str(fmt.str) {}
26582666

2659-
// Returning by reference generates better code in debug mode.
2660-
FMT_ALWAYS_INLINE operator const string_view&() const { return str; }
2667+
FMT_DEPRECATED operator const string_view&() const { return str; }
26612668
auto get() const -> string_view { return str; }
26622669
};
26632670

include/fmt/format.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,6 @@
121121
# define FMT_NOINLINE
122122
#endif
123123

124-
#ifdef FMT_DEPRECATED
125-
// Use the provided definition.
126-
#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
127-
# define FMT_DEPRECATED [[deprecated]]
128-
#else
129-
# define FMT_DEPRECATED /* deprecated */
130-
#endif
131-
132124
// Detect constexpr std::string.
133125
#if !FMT_USE_CONSTEVAL
134126
# define FMT_USE_CONSTEXPR_STRING 0

include/fmt/xchar.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ template <typename Char, typename... T> struct basic_fstring {
109109
}
110110
basic_fstring(runtime_format_string<Char> fmt) : str_(fmt.str) {}
111111

112-
operator basic_string_view<Char>() const { return str_; }
112+
FMT_DEPRECATED operator basic_string_view<Char>() const { return str_; }
113113
auto get() const -> basic_string_view<Char> { return str_; }
114114
};
115115

@@ -172,14 +172,13 @@ auto vformat(basic_string_view<Char> fmt,
172172

173173
template <typename... T>
174174
auto format(wformat_string<T...> fmt, T&&... args) -> std::wstring {
175-
return vformat(fmt::wstring_view(fmt), fmt::make_wformat_args(args...));
175+
return vformat(fmt.get(), fmt::make_wformat_args(args...));
176176
}
177177

178178
template <typename OutputIt, typename... T>
179179
auto format_to(OutputIt out, wformat_string<T...> fmt, T&&... args)
180180
-> OutputIt {
181-
return vformat_to(out, fmt::wstring_view(fmt),
182-
fmt::make_wformat_args(args...));
181+
return vformat_to(out, fmt.get(), fmt::make_wformat_args(args...));
183182
}
184183

185184
// Pass char_t as a default template parameter instead of using
@@ -301,11 +300,11 @@ inline void vprint(wstring_view fmt, wformat_args args) {
301300

302301
template <typename... T>
303302
void print(std::FILE* f, wformat_string<T...> fmt, T&&... args) {
304-
return vprint(f, wstring_view(fmt), fmt::make_wformat_args(args...));
303+
return vprint(f, fmt.get(), fmt::make_wformat_args(args...));
305304
}
306305

307306
template <typename... T> void print(wformat_string<T...> fmt, T&&... args) {
308-
return vprint(wstring_view(fmt), fmt::make_wformat_args(args...));
307+
return vprint(fmt.get(), fmt::make_wformat_args(args...));
309308
}
310309

311310
template <typename... T>
@@ -327,7 +326,7 @@ inline auto vformat(text_style ts, wstring_view fmt, wformat_args args)
327326
template <typename... T>
328327
inline auto format(text_style ts, wformat_string<T...> fmt, T&&... args)
329328
-> std::wstring {
330-
return fmt::vformat(ts, fmt, fmt::make_wformat_args(args...));
329+
return fmt::vformat(ts, fmt.get(), fmt::make_wformat_args(args...));
331330
}
332331

333332
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) {
338337

339338
template <typename... T>
340339
void print(std::wostream& os, wformat_string<T...> fmt, T&&... args) {
341-
vprint(os, fmt, fmt::make_format_args<buffered_context<wchar_t>>(args...));
340+
vprint(os, fmt.get(),
341+
fmt::make_format_args<buffered_context<wchar_t>>(args...));
342342
}
343343

344344
template <typename... T>

0 commit comments

Comments
 (0)