From cad876be4c854d0bcde239a80de87edc10bec8d4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 6 Sep 2024 12:09:56 -0700 Subject: [PATCH] Switch to vargs --- include/fmt/color.h | 6 +++--- include/fmt/format.h | 11 +++++------ include/fmt/os.h | 10 +++++----- include/fmt/ostream.h | 8 +++----- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index 231d93c8..d584ce3f 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -485,7 +485,7 @@ inline void vprint(FILE* f, const text_style& ts, string_view fmt, template void print(FILE* f, const text_style& ts, format_string fmt, T&&... args) { - vprint(f, ts, fmt, fmt::make_format_args(args...)); + vprint(f, ts, fmt, vargs{{args...}}); } /** @@ -524,7 +524,7 @@ inline auto vformat(const text_style& ts, string_view fmt, format_args args) template inline auto format(const text_style& ts, format_string fmt, T&&... args) -> std::string { - return fmt::vformat(ts, fmt, fmt::make_format_args(args...)); + return fmt::vformat(ts, fmt, vargs{{args...}}); } /// Formats a string with the given text_style and writes the output to `out`. @@ -551,7 +551,7 @@ template ::value)> inline auto format_to(OutputIt out, const text_style& ts, format_string fmt, T&&... args) -> OutputIt { - return vformat_to(out, ts, fmt, fmt::make_format_args(args...)); + return vformat_to(out, ts, fmt, vargs{{args...}}); } template diff --git a/include/fmt/format.h b/include/fmt/format.h index 061cb129..f9f6c457 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3923,7 +3923,7 @@ FMT_API auto vsystem_error(int error_code, string_view format_str, template auto system_error(int error_code, format_string fmt, T&&... args) -> std::system_error { - return vsystem_error(error_code, fmt, fmt::make_format_args(args...)); + return vsystem_error(error_code, fmt, vargs{{args...}}); } /** @@ -4331,7 +4331,7 @@ FMT_API auto vformat(string_view fmt, format_args args) -> std::string; template FMT_NODISCARD FMT_INLINE auto format(format_string fmt, T&&... args) -> std::string { - return vformat(fmt, fmt::make_format_args(args...)); + return vformat(fmt, vargs{{args...}}); } template ::value)> @@ -4344,7 +4344,7 @@ template ::value)> inline auto format(const Locale& loc, format_string fmt, T&&... args) -> std::string { - return fmt::vformat(loc, string_view(fmt), fmt::make_format_args(args...)); + return fmt::vformat(loc, string_view(fmt), vargs{{args...}}); } template ::value)> FMT_INLINE auto format_to(OutputIt out, const Locale& loc, format_string fmt, T&&... args) -> OutputIt { - return vformat_to(out, loc, fmt, fmt::make_format_args(args...)); + return vformat_to(out, loc, fmt, vargs{{args...}}); } template fmt, T&&... args) -> size_t { auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, fmt, fmt::make_format_args(args...), - detail::locale_ref(loc)); + detail::vformat_to(buf, fmt, vargs{{args...}}, detail::locale_ref(loc)); return buf.count(); } diff --git a/include/fmt/os.h b/include/fmt/os.h index 218721b9..4158b844 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -146,10 +146,10 @@ FMT_API std::system_error vwindows_error(int error_code, string_view format_str, * "cannot open file '{}'", filename); * } */ -template +template std::system_error windows_error(int error_code, string_view message, - const Args&... args) { - return vwindows_error(error_code, message, fmt::make_format_args(args...)); + const T&... args) { + return vwindows_error(error_code, message, vargs{{args...}}); } // Reports a Windows error without throwing an exception. @@ -213,7 +213,7 @@ class buffered_file { template inline void print(string_view fmt, const T&... args) { - const auto& vargs = fmt::make_format_args(args...); + fmt::vargs vargs = {{args...}}; detail::is_locking() ? fmt::vprint_buffered(file_, fmt, vargs) : fmt::vprint(file_, fmt, vargs); } @@ -398,7 +398,7 @@ class FMT_API ostream : private detail::buffer { /// Formats `args` according to specifications in `fmt` and writes the /// output to the file. template void print(format_string fmt, T&&... args) { - vformat_to(appender(*this), fmt, fmt::make_format_args(args...)); + vformat_to(appender(*this), fmt, vargs{{args...}}); } }; diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index b215af28..3a24ca03 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -178,11 +178,9 @@ void vprint(std::basic_ostream& os, */ FMT_EXPORT template void print(std::ostream& os, format_string fmt, T&&... args) { - const auto& vargs = fmt::make_format_args(args...); - if (FMT_USE_UTF8) - vprint(os, fmt, vargs); - else - detail::vprint_directly(os, fmt, vargs); + fmt::vargs vargs = {{args...}}; + if (FMT_USE_UTF8) return vprint(os, fmt, vargs); + detail::vprint_directly(os, fmt, vargs); } FMT_EXPORT