Add a Print overload that writes to a file.
This commit is contained in:
@@ -1062,7 +1062,6 @@ class BasicWriter {
|
||||
*/
|
||||
BasicFormatter<Char> Format(StringRef format);
|
||||
|
||||
// TODO: ArgInfo should be made public for this to be usable
|
||||
inline void VFormat(BasicStringRef<Char> format,
|
||||
std::size_t num_args, const ArgInfo *args) {
|
||||
FormatParser().Format(*this, format, num_args, args);
|
||||
@@ -1619,12 +1618,19 @@ class FileSink {
|
||||
// Formats a string and prints it to stdout.
|
||||
// Example:
|
||||
// Print("Elapsed time: {0:.2f} seconds") << 1.23;
|
||||
// TODO: wchar overload
|
||||
inline Formatter<FileSink> Print(StringRef format) {
|
||||
Formatter<FileSink> f(format, FileSink(stdout));
|
||||
return f;
|
||||
}
|
||||
|
||||
// Formats a string and prints it to a file.
|
||||
// Example:
|
||||
// Print(stderr, "Don't {}!") << "panic";
|
||||
inline Formatter<FileSink> Print(std::FILE *file, StringRef format) {
|
||||
Formatter<FileSink> f(format, FileSink(file));
|
||||
return f;
|
||||
}
|
||||
|
||||
enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
|
||||
|
||||
/**
|
||||
@@ -1680,6 +1686,13 @@ void Print(StringRef format, const Args & ... args) {
|
||||
std::fwrite(w.data(), 1, w.size(), stdout);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void Print(std::FILE *f, StringRef format, const Args & ... args) {
|
||||
Writer w;
|
||||
w.Format(format, args...);
|
||||
std::fwrite(w.data(), 1, w.size(), f);
|
||||
}
|
||||
|
||||
#endif // FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user