diff --git a/include/fmt/base.h b/include/fmt/base.h index 2028d82b..8f4c9899 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -15,7 +15,7 @@ #ifndef FMT_MODULE # include // CHAR_BIT # include // FILE -# include // strlen +# include // memcmp // is also included transitively from . # include // std::byte @@ -2956,7 +2956,7 @@ template ::value)> FMT_INLINE auto format_to(OutputIt&& out, format_string fmt, T&&... args) -> remove_cvref_t { - return vformat_to(FMT_FWD(out), fmt, vargs{{args...}}); + return vformat_to(FMT_FWD(out), fmt.str, vargs{{args...}}); } template struct format_to_n_result { @@ -2986,7 +2986,7 @@ template ::value)> FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string fmt, T&&... args) -> format_to_n_result { - return vformat_to_n(out, n, fmt, vargs{{args...}}); + return vformat_to_n(out, n, fmt.str, vargs{{args...}}); } struct format_to_result { @@ -3041,8 +3041,9 @@ FMT_API void vprintln(FILE* f, string_view fmt, format_args args); template FMT_INLINE void print(format_string fmt, T&&... args) { fmt::vargs vargs = {{args...}}; - if (!FMT_USE_UTF8) return detail::vprint_mojibake(stdout, fmt, vargs, false); - return detail::is_locking() ? vprint_buffered(stdout, fmt, vargs) + if (!FMT_USE_UTF8) + return detail::vprint_mojibake(stdout, fmt.str, vargs, false); + return detail::is_locking() ? vprint_buffered(stdout, fmt.str, vargs) : vprint(fmt.str, vargs); } @@ -3057,8 +3058,8 @@ FMT_INLINE void print(format_string fmt, T&&... args) { template FMT_INLINE void print(FILE* f, format_string fmt, T&&... args) { fmt::vargs vargs = {{args...}}; - if (!FMT_USE_UTF8) return detail::vprint_mojibake(f, fmt, vargs, false); - return detail::is_locking() ? vprint_buffered(f, fmt, vargs) + if (!FMT_USE_UTF8) return detail::vprint_mojibake(f, fmt.str, vargs, false); + return detail::is_locking() ? vprint_buffered(f, fmt.str, vargs) : vprint(f, fmt.str, vargs); } @@ -3067,8 +3068,8 @@ FMT_INLINE void print(FILE* f, format_string fmt, T&&... args) { template FMT_INLINE void println(FILE* f, format_string fmt, T&&... args) { fmt::vargs vargs = {{args...}}; - return FMT_USE_UTF8 ? vprintln(f, fmt, vargs) - : detail::vprint_mojibake(f, fmt, vargs, true); + return FMT_USE_UTF8 ? vprintln(f, fmt.str, vargs) + : detail::vprint_mojibake(f, fmt.str, vargs, true); } /// Formats `args` according to specifications in `fmt` and writes the output diff --git a/include/fmt/color.h b/include/fmt/color.h index ae63b940..2faaf3a0 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -484,7 +484,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, vargs{{args...}}); + vprint(f, ts, fmt.str, vargs{{args...}}); } /** @@ -523,7 +523,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, vargs{{args...}}); + return fmt::vformat(ts, fmt.str, vargs{{args...}}); } /// Formats a string with the given text_style and writes the output to `out`. @@ -550,7 +550,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, vargs{{args...}}); + return vformat_to(out, ts, fmt.str, vargs{{args...}}); } template diff --git a/include/fmt/format.h b/include/fmt/format.h index ad7981cb..911628e8 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3919,7 +3919,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, vargs{{args...}}); + return vsystem_error(error_code, fmt.str, vargs{{args...}}); } /** @@ -4327,7 +4327,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, vargs{{args...}}); + return vformat(fmt.str, vargs{{args...}}); } template ::value)> @@ -4340,7 +4340,7 @@ template ::value)> inline auto format(const Locale& loc, format_string fmt, T&&... args) -> std::string { - return fmt::vformat(loc, string_view(fmt), vargs{{args...}}); + return fmt::vformat(loc, fmt.str, 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, vargs{{args...}}); + return vformat_to(out, loc, fmt.str, vargs{{args...}}); } template fmt, T&&... args) -> size_t { auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, fmt, vargs{{args...}}, detail::locale_ref(loc)); + detail::vformat_to(buf, fmt.str, vargs{{args...}}, + detail::locale_ref(loc)); return buf.count(); } diff --git a/include/fmt/os.h b/include/fmt/os.h index 9e016536..393a5f65 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -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, vargs{{args...}}); + vformat_to(appender(*this), fmt.str, vargs{{args...}}); } }; diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 71f51904..18a8b88c 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -57,15 +57,6 @@ void write_buffer(std::basic_ostream& os, buffer& buf) { } while (size != 0); } -template -void format_value(buffer& buf, const T& value) { - auto&& format_buf = formatbuf>(buf); - auto&& output = std::basic_ostream(&format_buf); - output.imbue(std::locale::classic()); // The default is always unlocalized. - output << value; - output.exceptions(std::ios_base::failbit | std::ios_base::badbit); -} - template struct streamed_view { const T& value; }; @@ -79,7 +70,11 @@ struct basic_ostream_formatter : formatter, Char> { template auto format(const T& value, Context& ctx) const -> decltype(ctx.out()) { auto buffer = basic_memory_buffer(); - detail::format_value(buffer, value); + auto&& formatbuf = detail::formatbuf>(buffer); + auto&& output = std::basic_ostream(&formatbuf); + output.imbue(std::locale::classic()); // The default is always unlocalized. + output << value; + output.exceptions(std::ios_base::failbit | std::ios_base::badbit); return formatter, Char>::format( {buffer.data(), buffer.size()}, ctx); } @@ -147,9 +142,9 @@ inline void vprint(std::ostream& os, string_view fmt, format_args args) { FMT_EXPORT template void print(std::ostream& os, format_string fmt, T&&... args) { fmt::vargs vargs = {{args...}}; - if (FMT_USE_UTF8) return vprint(os, fmt, vargs); + if (FMT_USE_UTF8) return vprint(os, fmt.str, vargs); auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, vargs); + detail::vformat_to(buffer, fmt.str, vargs); detail::write_buffer(os, buffer); }