Codemod folly::make_unique to std::make_unique
[folly.git] / folly / Try.h
index edfe6a7e3e450f5e386ed7a3effd88be073c3dd5..86a5dee003c9b37b98e4312c900fd96943ac0aba 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.
 
 #pragma once
 
-#include <type_traits>
-#include <exception>
-#include <algorithm>
 #include <folly/ExceptionWrapper.h>
 #include <folly/Likely.h>
 #include <folly/Memory.h>
 #include <folly/Portability.h>
 #include <folly/Unit.h>
+#include <exception>
+#include <stdexcept>
+#include <type_traits>
+#include <utility>
 
 namespace folly {
 
-class TryException : public std::exception {
+class TryException : public std::logic_error {
  public:
-  explicit TryException(std::string message_arg) noexcept
-      : message(std::move(message_arg)) {}
-
-  const char* what() const noexcept override {
-    return message.c_str();
-  }
-
-  bool operator==(const TryException& other) const noexcept {
-    return other.message == this->message;
-  }
-
-  bool operator!=(const TryException& other) const noexcept {
-    return !(*this == other);
-  }
-
- protected:
-  std::string message;
+  using std::logic_error::logic_error;
 };
 
 class UsingUninitializedTry : public TryException {
  public:
-  UsingUninitializedTry() noexcept : TryException("Using unitialized try") {}
+  UsingUninitializedTry() : TryException("Using uninitialized try") {}
 };
 
 /*
@@ -108,8 +93,8 @@ class Try {
    * @param e The exception_wrapper
    */
   explicit Try(exception_wrapper e)
-    : contains_(Contains::EXCEPTION),
-      e_(folly::make_unique<exception_wrapper>(std::move(e))) {}
+      : contains_(Contains::EXCEPTION),
+        e_(std::make_unique<exception_wrapper>(std::move(e))) {}
 
   /*
    * DEPRECATED
@@ -123,9 +108,9 @@ class Try {
     try {
       std::rethrow_exception(ep);
     } catch (const std::exception& e) {
-      e_ = folly::make_unique<exception_wrapper>(std::current_exception(), e);
+      e_ = std::make_unique<exception_wrapper>(std::current_exception(), e);
     } catch (...) {
-      e_ = folly::make_unique<exception_wrapper>(std::current_exception());
+      e_ = std::make_unique<exception_wrapper>(std::current_exception());
     }
   }
 
@@ -281,8 +266,8 @@ class Try<void> {
    * @param e The exception_wrapper
    */
   explicit Try(exception_wrapper e)
-    : hasValue_(false),
-      e_(folly::make_unique<exception_wrapper>(std::move(e))) {}
+      : hasValue_(false),
+        e_(std::make_unique<exception_wrapper>(std::move(e))) {}
 
   /*
    * DEPRECATED
@@ -295,9 +280,9 @@ class Try<void> {
     try {
       std::rethrow_exception(ep);
     } catch (const std::exception& e) {
-      e_ = folly::make_unique<exception_wrapper>(std::current_exception(), e);
+      e_ = std::make_unique<exception_wrapper>(std::current_exception(), e);
     } catch (...) {
-      e_ = folly::make_unique<exception_wrapper>(std::current_exception());
+      e_ = std::make_unique<exception_wrapper>(std::current_exception());
     }
   }
 
@@ -305,7 +290,7 @@ class Try<void> {
   Try& operator=(const Try<void>& t) {
     hasValue_ = t.hasValue_;
     if (t.e_) {
-      e_ = folly::make_unique<exception_wrapper>(*t.e_);
+      e_ = std::make_unique<exception_wrapper>(*t.e_);
     }
     return *this;
   }
@@ -418,6 +403,9 @@ typename std::enable_if<
   Try<void>>::type
 makeTryWith(F&& f);
 
+template <typename... Ts>
+std::tuple<Ts...> unwrapTryTuple(std::tuple<folly::Try<Ts>...>&& ts);
+
 } // folly
 
 #include <folly/Try-inl.h>