bug fix when rallocm fails
[folly.git] / folly / Format.h
index 628a2a29fd0ffbcea69895ebb5e6ad6439ae7298..589bcdff4b59d3f18f3100a299b56010a5a72fa6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -18,6 +18,7 @@
 #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
@@ -71,7 +76,7 @@ class Formatter {
    * 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);
@@ -117,7 +122,7 @@ class Formatter {
   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>
@@ -150,11 +155,18 @@ std::ostream& operator<<(std::ostream& out,
   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) {
@@ -190,7 +202,7 @@ Formatter<true, Container> vformat(StringPiece fmt, Container&& container) {
  * 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);
 }
@@ -199,7 +211,7 @@ format(Str* out, StringPiece fmt, Args&&... args) {
  * 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);
 }
@@ -268,5 +280,6 @@ void formatFormatter(const Formatter<containerMode, Args...>& formatter,
 
 #include "folly/Format-inl.h"
 
-#endif /* FOLLY_FORMAT_H_ */
+#pragma GCC diagnostic pop
 
+#endif /* FOLLY_FORMAT_H_ */