diff --git a/include/fmt/core.h b/include/fmt/core.h index 708d8589af43..bcc3aa0f5d45 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1295,8 +1295,9 @@ template struct is_format_string : std::is_empty> {}; template -struct is_compile_string : - std::integral_constant::value> {}; +struct is_compile_string : std::is_base_of {}; + +#define FMT_CHAR(Str) typename internal::format_string_traits::char_type template inline typename std::enable_if::value>::type @@ -1346,26 +1347,20 @@ typename std::enable_if< return out; } -template -inline typename std::enable_if< - is_contiguous::value, std::back_insert_iterator>::type - format_to(std::back_insert_iterator out, - string_view format_str, const Args &... args) { - format_arg_store as{args...}; - return vformat_to(out, format_str, as); -} - -template +#define FMT_CHAR(Str) typename internal::format_string_traits::char_type +template inline typename std::enable_if< - is_contiguous::value, std::back_insert_iterator>::type + is_contiguous::value && internal::is_format_string::value, + std::back_insert_iterator>::type format_to(std::back_insert_iterator out, - wstring_view format_str, const Args &... args) { - return vformat_to(out, format_str, - make_format_args(args...)); + const String &format_str, const Args &... args) { + internal::check_format_string(format_str); + typedef typename buffer_context< FMT_CHAR(String) >::type context_t; + format_arg_store as{args...}; + return vformat_to(out, basic_string_view< FMT_CHAR(String) >(format_str), + basic_format_args(as)); } -#define FMT_CHAR(Str) typename internal::format_string_traits::char_type - template inline std::basic_string vformat( const String &format_str, @@ -1402,26 +1397,24 @@ FMT_API void vprint(std::FILE *f, wstring_view format_str, wformat_args args); /** \rst - Prints formatted data to the file *f*. + Prints formatted data to the file *f*. For wide format strings, + *f* should be in wide-oriented mode set via ``fwide(f, 1)`` or + ``_setmode(_fileno(f), _O_U8TEXT)`` on Windows. **Example**:: fmt::print(stderr, "Don't {}!", "panic"); + \endrst */ -template -inline void print(std::FILE *f, string_view format_str, const Args &... args) { - format_arg_store as(args...); - vprint(f, format_str, as); -} -/** - Prints formatted data to the file *f* which should be in wide-oriented mode - set via ``fwide(f, 1)`` or ``_setmode(_fileno(f), _O_U8TEXT)`` on Windows. - */ -template -inline void print(std::FILE *f, wstring_view format_str, const Args &... args) { - format_arg_store as(args...); - vprint(f, format_str, as); +template +inline typename std::enable_if::value>::type +print(std::FILE *f, const String &format_str, const Args &... args) { + internal::check_format_string(format_str); + typedef typename buffer_context< FMT_CHAR(String) >::type context_t; + format_arg_store as{ args... }; + vprint(f, basic_string_view< FMT_CHAR(String) >(format_str), + basic_format_args(as)); } FMT_API void vprint(string_view format_str, format_args args); @@ -1436,16 +1429,14 @@ FMT_API void vprint(wstring_view format_str, wformat_args args); fmt::print("Elapsed time: {0:.2f} seconds", 1.23); \endrst */ -template -inline void print(string_view format_str, const Args &... args) { - format_arg_store as{args...}; - vprint(format_str, as); -} - -template -inline void print(wstring_view format_str, const Args &... args) { - format_arg_store as(args...); - vprint(format_str, as); +template +inline typename std::enable_if::value>::type +print(const String &format_str, const Args &... args) { + internal::check_format_string(format_str); + typedef typename buffer_context< FMT_CHAR(String) >::type context_t; + format_arg_store as{ args... }; + vprint(basic_string_view< FMT_CHAR(String) >(format_str), + basic_format_args(as)); } FMT_END_NAMESPACE