@@ -95,8 +95,7 @@ inline bool write_ostream_unicode(std::ostream& os, fmt::string_view data) {
9595 if (auto * buf = dynamic_cast <std::__stdoutbuf<char >*>(os.rdbuf ()))
9696 if (FILE* f = get_file (*buf)) return write_console (f, data);
9797#else
98- ignore_unused (os);
99- ignore_unused (data);
98+ ignore_unused (os, data);
10099#endif
101100 return false ;
102101}
@@ -109,7 +108,6 @@ inline bool write_ostream_unicode(std::wostream&,
109108// It is a separate function rather than a part of vprint to simplify testing.
110109template <typename Char>
111110void write_buffer (std::basic_ostream<Char>& os, buffer<Char>& buf) {
112- if (write_ostream_unicode (os, {buf.data (), buf.size ()})) return ;
113111 const Char* buf_data = buf.data ();
114112 using unsigned_streamsize = std::make_unsigned<std::streamsize>::type;
115113 unsigned_streamsize size = buf.size ();
@@ -189,6 +187,17 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
189187 using basic_ostream_formatter<Char>::format;
190188};
191189
190+ inline void vprint_directly (std::ostream& os, string_view format_str,
191+ format_args args) {
192+ #ifdef _WIN32
193+ auto buffer = memory_buffer ();
194+ detail::vformat_to (buffer, format_str, args);
195+ detail::write_buffer (os, buffer);
196+ #else
197+ ignore_unused (os, format_str, args);
198+ #endif
199+ }
200+
192201} // namespace detail
193202
194203FMT_MODULE_EXPORT template <typename Char>
@@ -197,6 +206,7 @@ void vprint(std::basic_ostream<Char>& os,
197206 basic_format_args<buffer_context<type_identity_t <Char>>> args) {
198207 auto buffer = basic_memory_buffer<Char>();
199208 detail::vformat_to (buffer, format_str, args);
209+ if (detail::write_ostream_unicode (os, {buffer.data (), buffer.size ()})) return ;
200210 detail::write_buffer (os, buffer);
201211}
202212
@@ -211,7 +221,11 @@ void vprint(std::basic_ostream<Char>& os,
211221 */
212222FMT_MODULE_EXPORT template <typename ... T>
213223void print (std::ostream& os, format_string<T...> fmt, T&&... args) {
214- vprint (os, fmt, fmt::make_format_args (args...));
224+ const auto & vargs = fmt::make_format_args (args...);
225+ if (detail::is_utf8 ())
226+ vprint (os, fmt, vargs);
227+ else
228+ detail::vprint_directly (os, fmt, vargs);
215229}
216230
217231FMT_MODULE_EXPORT
0 commit comments