Skip to content

Commit

Permalink
Fix fmtlib#2817: add compile-time checking to ostream overloads of fm…
Browse files Browse the repository at this point in the history
…t::print
  • Loading branch information
timsong-cpp committed Mar 18, 2022
1 parent 7207bd1 commit acd2ceb
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <ostream>

#include "format.h"
#include "xchar.h"

FMT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -115,7 +116,8 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>

FMT_MODULE_EXPORT
template <typename Char>
void vprint(std::basic_ostream<Char>& os, basic_string_view<Char> format_str,
void vprint(std::basic_ostream<Char>& os,
basic_string_view<type_identity_t<Char>> format_str,
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
auto buffer = basic_memory_buffer<Char>();
detail::vformat_to(buffer, format_str, args);
Expand All @@ -132,12 +134,17 @@ void vprint(std::basic_ostream<Char>& os, basic_string_view<Char> format_str,
\endrst
*/
FMT_MODULE_EXPORT
template <typename S, typename... Args,
typename Char = enable_if_t<detail::is_string<S>::value, char_t<S>>>
void print(std::basic_ostream<Char>& os, const S& format_str, Args&&... args) {
vprint(os, to_string_view(format_str),
fmt::make_format_args<buffer_context<Char>>(args...));
template <typename... Args>
void print(std::ostream& os, format_string<Args...> fmt, Args&&... args) {
vprint(os, fmt, fmt::make_format_args(args...));
}

FMT_MODULE_EXPORT
template <typename... Args>
void print(std::wostream& os, wformat_string<Args...> fmt, Args&&... args) {
vprint(os, fmt, fmt::make_wformat_args(args...));
}

FMT_END_NAMESPACE

#endif // FMT_OSTREAM_H_

0 comments on commit acd2ceb

Please sign in to comment.