diff --git a/format.cc b/format.cc index a3ea9de5..63d4e5e3 100644 --- a/format.cc +++ b/format.cc @@ -1111,6 +1111,18 @@ void fmt::print(StringRef format, const ArgList &args) { std::fwrite(w.data(), 1, w.size(), stdout); } +void fmt::print(std::FILE *f, StringRef format, const ArgList &args) { + Writer w; + w.format(format, args); + std::fwrite(w.data(), 1, w.size(), f); +} + +void fmt::printf(StringRef format, const ArgList &args) { + Writer w; + w.printf(format, args); + std::fwrite(w.data(), 1, w.size(), stdout); +} + // Explicit instantiations for char. template fmt::BasicWriter::CharPtr diff --git a/format.h b/format.h index 14d37161..7a1ff7db 100644 --- a/format.h +++ b/format.h @@ -1962,6 +1962,15 @@ inline WWriter format(WStringRef format, const ArgList &args) { } void print(StringRef format, const ArgList &args); +void print(std::FILE *f, StringRef format, const ArgList &args); + +inline Writer sprintf(StringRef format, const ArgList &args) { + Writer w; + w.printf(format, args); + return move(w); +} + +void printf(StringRef format, const ArgList &args); #if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES @@ -2005,6 +2014,10 @@ void Print(StringRef format, const Args & ... args) { std::fwrite(w.data(), 1, w.size(), stdout); } +// This function is deprecated, use fmt::print instead. +template +FMT_DEPRECATED(void Print(std::FILE *f, StringRef format, const Args & ... args)); + template void Print(std::FILE *f, StringRef format, const Args & ... args) { Writer w; @@ -2012,20 +2025,6 @@ void Print(std::FILE *f, StringRef format, const Args & ... args) { std::fwrite(w.data(), 1, w.size(), f); } -template -inline Writer sprintf(StringRef format, const Args & ... args) { - Writer w; - w.printf(format, args...); - return std::move(w); -} - -template -void printf(StringRef format, const Args & ... args) { - Writer w; - w.printf(format, args...); - std::fwrite(w.data(), 1, w.size(), stdout); -} - #endif // FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES /** @@ -2224,9 +2223,12 @@ inline void FormatDec(char *&buffer, T value) { FMT_VARIADIC_(wchar_t, ReturnType, func, __VA_ARGS__) namespace fmt { -FMT_VARIADIC(fmt::Writer, format, fmt::StringRef) -FMT_VARIADIC_W(fmt::WWriter, format, fmt::WStringRef) -FMT_VARIADIC(void, print, fmt::StringRef) +FMT_VARIADIC(Writer, format, StringRef) +FMT_VARIADIC_W(WWriter, format, WStringRef) +FMT_VARIADIC(void, print, StringRef) +FMT_VARIADIC(void, print, std::FILE *, StringRef) +FMT_VARIADIC(Writer, sprintf, StringRef) +FMT_VARIADIC(void, printf, StringRef) } // Restore warnings. diff --git a/test/format-test.cc b/test/format-test.cc index 49d61992..3883f799 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1590,16 +1590,9 @@ TEST(FormatIntTest, FormatDec) { TEST(FormatTest, Print) { EXPECT_WRITE(stdout, fmt::print("Don't {}!", "panic"), "Don't panic!"); EXPECT_WRITE(stderr, - fmt::Print(stderr, "Don't {}!") << "panic", "Don't panic!"); + fmt::print(stderr, "Don't {}!", "panic"), "Don't panic!"); } -#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES -TEST(FormatTest, PrintVariadic) { - EXPECT_WRITE(stderr, - fmt::Print(stderr, "Don't {}!", "panic"), "Don't panic!"); -} -#endif // FMT_USE_VARIADIC_TEMPLATES - TEST(FormatTest, PrintColored) { EXPECT_WRITE(stdout, fmt::PrintColored(fmt::RED, "Hello, {}!\n") << "world", "\x1b[31mHello, world!\n\x1b[0m"); diff --git a/test/printf-test.cc b/test/printf-test.cc index bf34e514..26a78734 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -32,8 +32,6 @@ #include "gtest-extra.h" #include "util.h" -#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES - using fmt::format; using fmt::FormatError; @@ -283,5 +281,3 @@ TEST(PrintfTest, Length) { } // TODO: test type specifier - -#endif