No need for a wrapping structure for posixTimeToDuration
[folly.git] / folly / FormatArg.h
index 33eb262489234dda4a32af0d7384fb73ba4b9740..a6d4fb63865eb3b7cd0cf0faec1641274f0b10f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
 #pragma once
 
 #include <stdexcept>
+
 #include <folly/Conv.h>
 #include <folly/Likely.h>
 #include <folly/Portability.h>
 namespace folly {
 
 class BadFormatArg : public std::invalid_argument {
- public:
-  explicit BadFormatArg(const std::string& msg)
-    : std::invalid_argument(msg) {}
+  using invalid_argument::invalid_argument;
 };
 
+[[noreturn]] void throwBadFormatArg(char const* msg);
+[[noreturn]] void throwBadFormatArg(std::string const& msg);
+
 /**
  * Parsed format argument.
  */
@@ -212,7 +214,7 @@ inline std::string FormatArg::errorStr(Args&&... args) const {
 
 template <typename... Args>
 [[noreturn]] inline void FormatArg::error(Args&&... args) const {
-  throw BadFormatArg(errorStr(std::forward<Args>(args)...));
+  throwBadFormatArg(errorStr(std::forward<Args>(args)...));
 }
 
 template <bool emptyOk>
@@ -244,7 +246,7 @@ inline StringPiece FormatArg::doSplitKey() {
   if (e[-1] == ']') {
     --e;
     p = static_cast<const char*>(memchr(b, '[', size_t(e - b)));
-    enforce(p, "unmatched ']'");
+    enforce(p != nullptr, "unmatched ']'");
   } else {
     p = static_cast<const char*>(memchr(b, '.', size_t(e - b)));
   }
@@ -273,4 +275,4 @@ inline int FormatArg::splitIntKey() {
   }
 }
 
-}  // namespace folly
+} // namespace folly