diff --git a/include/fmt/core.h b/include/fmt/core.h index ac50a7d4..5572e682 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1068,6 +1068,8 @@ class format_arg_store { format_arg_store(const Args &... args) : data_{internal::make_arg(args)...} {} #endif + + basic_format_args operator*() const { return *this; } }; #if !FMT_USE_CONSTEXPR11 @@ -1296,30 +1298,30 @@ struct is_compile_string : std::is_base_of {}; template inline typename std::enable_if::value>::type - check_format_string(const S &) {} + check_format_string(const S &) {} template typename std::enable_if::value>::type - check_format_string(S); + check_format_string(S); template std::basic_string vformat( - basic_string_view format_str, - basic_format_args::type> args); + basic_string_view format_str, + basic_format_args::type> args); } // namespace internal -template +template format_context::iterator vformat_to( - internal::basic_buffer &buf, const String &format_str, - basic_format_args > args); + internal::basic_buffer &buf, const S &format_str, + basic_format_args > args); template -struct is_contiguous : std::false_type {}; +struct is_contiguous: std::false_type {}; template -struct is_contiguous> : std::true_type {}; +struct is_contiguous >: std::true_type {}; template -struct is_contiguous> : std::true_type {}; +struct is_contiguous >: std::true_type {}; /** Formats a string and writes the output to ``out``. */ template @@ -1335,29 +1337,28 @@ typename std::enable_if< template typename std::enable_if< is_contiguous::value, std::back_insert_iterator>::type - vformat_to(std::back_insert_iterator out, - wstring_view format_str, wformat_args args) { + vformat_to(std::back_insert_iterator out, + wstring_view format_str, wformat_args args) { internal::container_buffer buf(internal::get_container(out)); vformat_to(buf, format_str, args); return out; } -template +template inline typename std::enable_if< - is_contiguous::value && internal::is_format_string::value, + is_contiguous::value && internal::is_format_string::value, std::back_insert_iterator>::type - format_to(std::back_insert_iterator out, - const String &format_str, const Args &... args) { + format_to(std::back_insert_iterator out, const S &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)); + format_arg_store< + typename buffer_context::type, Args...> as(args...); + return vformat_to(out, basic_string_view(format_str), as); } -template +template inline std::basic_string vformat( - const String &format_str, + 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); @@ -1373,17 +1374,16 @@ inline std::basic_string vformat( std::string message = fmt::format("The answer is {}", 42); \endrst */ -template -inline std::basic_string< FMT_CHAR(String)> format( - const String &format_str, const Args &... args) { +template +inline std::basic_string format( + const S &format_str, const Args &... args) { internal::check_format_string(format_str); // This should be just // return vformat(format_str, make_format_args(args...)); // but gcc has trouble optimizing the latter, so break it down. - typedef typename buffer_context< FMT_CHAR(String)>::type context_t; - format_arg_store as{args...}; - return internal::vformat(basic_string_view(format_str), - basic_format_args(as)); + format_arg_store< + typename buffer_context::type, Args...> as(args...); + return internal::vformat(basic_string_view(format_str), *as); } FMT_API void vprint(std::FILE *f, string_view format_str, format_args args); @@ -1398,17 +1398,15 @@ FMT_API void vprint(std::FILE *f, wstring_view format_str, wformat_args args); **Example**:: fmt::print(stderr, "Don't {}!", "panic"); - \endrst */ -template -inline typename std::enable_if::value>::type -print(std::FILE *f, const String &format_str, const Args &... args) { +template +inline typename std::enable_if::value>::type + print(std::FILE *f, const S &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)); + format_arg_store< + typename buffer_context::type, Args...> as(args...); + vprint(f, basic_string_view(format_str), as); } FMT_API void vprint(string_view format_str, format_args args); @@ -1423,14 +1421,13 @@ FMT_API void vprint(wstring_view format_str, wformat_args args); fmt::print("Elapsed time: {0:.2f} seconds", 1.23); \endrst */ -template -inline typename std::enable_if::value>::type -print(const String &format_str, const Args &... args) { +template +inline typename std::enable_if::value>::type + print(const S &format_str, const Args &... args) { internal::check_format_string(format_str); - typedef typename buffer_context::type context_t; - format_arg_store as{ args... }; - vprint(basic_string_view(format_str), - basic_format_args(as)); + format_arg_store< + typename buffer_context::type, Args...> as(args...); + vprint(basic_string_view(format_str), as); } FMT_END_NAMESPACE