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 61097cc commit bd75e24
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 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,7 @@ 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 +133,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 bd75e24

Please sign in to comment.