diff --git a/fmt/format.cc b/fmt/format.cc index 8b175bbf..3b46ded2 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -226,7 +226,7 @@ FMT_FUNC void SystemError::init( int err_code, CStringRef format_str, format_args args) { error_code_ = err_code; MemoryWriter w; - format_system_error(w, err_code, format(format_str, args)); + format_system_error(w, err_code, vformat(format_str, args)); std::runtime_error &base = *this; base = std::runtime_error(w.str()); } diff --git a/fmt/format.h b/fmt/format.h index 3bf486f0..10ae61bd 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -3122,6 +3122,12 @@ enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }; */ FMT_API void print_colored(Color c, CStringRef format, format_args args); +inline std::string vformat(CStringRef format_str, format_args args) { + MemoryWriter w; + w.write(format_str, args); + return w.str(); +} + /** \rst Formats arguments and returns the result as a string. @@ -3131,10 +3137,10 @@ FMT_API void print_colored(Color c, CStringRef format, format_args args); std::string message = format("The answer is {}", 42); \endrst */ -inline std::string format(CStringRef format_str, format_args args) { - MemoryWriter w; - w.write(format_str, args); - return w.str(); +template +inline std::string format(CStringRef format_str, const Args & ... args) { + auto vargs = internal::make_format_args>(args...); + vformat(format_str, format_args(vargs.TYPES, vargs.data())); } inline std::wstring format(WCStringRef format_str, format_args args) { @@ -3389,7 +3395,6 @@ void arg(WStringRef, const internal::NamedArg&) FMT_DELETED_OR_UNDEFINED; #define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__) namespace fmt { -FMT_VARIADIC(std::string, format, CStringRef) FMT_VARIADIC_W(std::wstring, format, WCStringRef) FMT_VARIADIC(void, print, CStringRef) FMT_VARIADIC(void, print, std::FILE *, CStringRef)