diff --git a/include/fmt/core.h b/include/fmt/core.h index 6fe15166..181001b5 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1314,6 +1314,11 @@ struct checked_args: format_arg_store< basic_format_args operator*() const { return *this; } }; +template +inline basic_string_view to_string_view(const S &s) { + return basic_string_view(s); +} + template std::basic_string vformat( basic_string_view format_str, @@ -1361,17 +1366,15 @@ inline typename std::enable_if< std::back_insert_iterator>::type format_to(std::back_insert_iterator out, const S &format_str, const Args &... args) { - return vformat_to( - out, basic_string_view(format_str), - internal::checked_args(format_str, args...)); + return vformat_to(out, internal::to_string_view(format_str), + internal::checked_args(format_str, args...)); } template inline std::basic_string vformat( const S &format_str, basic_format_args::type> args) { - // Convert format string to string_view to reduce the number of overloads. - return internal::vformat(basic_string_view(format_str), args); + return internal::vformat(internal::to_string_view(format_str), args); } /** @@ -1388,7 +1391,7 @@ template inline std::basic_string format( const S &format_str, const Args &... args) { return internal::vformat( - basic_string_view(format_str), + internal::to_string_view(format_str), *internal::checked_args(format_str, args...)); } @@ -1409,7 +1412,7 @@ FMT_API void vprint(std::FILE *f, wstring_view format_str, wformat_args args); template inline typename std::enable_if::value>::type print(std::FILE *f, const S &format_str, const Args &... args) { - vprint(f, basic_string_view(format_str), + vprint(f, internal::to_string_view(format_str), internal::checked_args(format_str, args...)); } @@ -1428,7 +1431,7 @@ FMT_API void vprint(wstring_view format_str, wformat_args args); template inline typename std::enable_if::value>::type print(const S &format_str, const Args &... args) { - vprint(basic_string_view(format_str), + vprint(internal::to_string_view(format_str), internal::checked_args(format_str, args...)); } FMT_END_NAMESPACE