/*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#define FOLLY_FORMAT_H_
#include <array>
+#include <cstdio>
#include <tuple>
#include <type_traits>
#include <vector>
#include "folly/small_vector.h"
#include "folly/FormatArg.h"
+// Ignore shadowing warnings within this file, so includers can use -Wshadow.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
+
namespace folly {
// forward declarations
* Append to a string.
*/
template <class Str>
- typename std::enable_if<detail::IsSomeString<Str>::value>::type
+ typename std::enable_if<IsSomeString<Str>::value>::type
appendTo(Str& str) const {
auto appender = [&str] (StringPiece s) { str.append(s.data(), s.size()); };
(*this)(appender);
template <size_t K, class Callback>
typename std::enable_if<K == valueCount>::type
doFormatFrom(size_t i, FormatArg& arg, Callback& cb) const {
- arg.error("argument index out of range, max=", i);
+ LOG(FATAL) << arg.errorStr("argument index out of range, max=", i);
}
template <size_t K, class Callback>
return out;
}
+/**
+ * Formatter objects can be written to stdio FILEs.
+ */
+template<bool containerMode, class... Args>
+void writeTo(FILE* fp, const Formatter<containerMode, Args...>& formatter);
+
/**
* Create a formatter object.
*
* std::string formatted = format("{} {}", 23, 42).str();
* LOG(INFO) << format("{} {}", 23, 42);
+ * writeTo(stdout, format("{} {}", 23, 42));
*/
template <class... Args>
Formatter<false, Args...> format(StringPiece fmt, Args&&... args) {
* Shortcut for toAppend(format(...), &foo);
*/
template <class Str, class... Args>
-typename std::enable_if<detail::IsSomeString<Str>::value>::type
+typename std::enable_if<IsSomeString<Str>::value>::type
format(Str* out, StringPiece fmt, Args&&... args) {
format(fmt, std::forward<Args>(args)...).appendTo(*out);
}
* Append vformatted output to a string.
*/
template <class Str, class Container>
-typename std::enable_if<detail::IsSomeString<Str>::value>::type
+typename std::enable_if<IsSomeString<Str>::value>::type
vformat(Str* out, StringPiece fmt, Container&& container) {
vformat(fmt, std::forward<Container>(container)).appendTo(*out);
}
#include "folly/Format-inl.h"
-#endif /* FOLLY_FORMAT_H_ */
+#pragma GCC diagnostic pop
+#endif /* FOLLY_FORMAT_H_ */