Use simpler tags for ctor dispatch in exception_wrapper
[folly.git] / folly / ExceptionWrapper.h
index 5f1d65a2cfa5cee6881a9ee7b62f39527fb52ac5..36913d85db9509088ed10475a004d960e7b11eb9 100644 (file)
@@ -29,7 +29,6 @@
 #include <typeinfo>
 #include <utility>
 
-#include <folly/Assume.h>
 #include <folly/CPortability.h>
 #include <folly/Demangle.h>
 #include <folly/ExceptionString.h>
@@ -37,6 +36,7 @@
 #include <folly/Portability.h>
 #include <folly/Traits.h>
 #include <folly/Utility.h>
+#include <folly/lang/Assume.h>
 
 #ifdef __GNUC__
 #pragma GCC diagnostic push
@@ -235,18 +235,16 @@ class exception_wrapper final {
     Ex const& as() const noexcept;
   };
 
-  enum class Placement { kInSitu, kOnHeap };
+  struct InSituTag {};
+  struct OnHeapTag {};
+
   template <class T>
-  using PlacementOf = std::integral_constant<
-      Placement,
+  using PlacementOf = _t<std::conditional<
       sizeof(T) <= sizeof(Buffer::Storage) &&
-              alignof(T) <= alignof(Buffer::Storage) &&
-              noexcept(T(std::declval<T&&>()))
-          ? Placement::kInSitu
-          : Placement::kOnHeap>;
-
-  using InSituTag = std::integral_constant<Placement, Placement::kInSitu>;
-  using OnHeapTag = std::integral_constant<Placement, Placement::kOnHeap>;
+          alignof(T) <= alignof(Buffer::Storage) &&
+          noexcept(T(std::declval<T&&>())),
+      InSituTag,
+      OnHeapTag>>;
 
   static std::exception const* as_exception_or_null_(std::exception const& ex);
   static std::exception const* as_exception_or_null_(AnyException);
@@ -368,6 +366,9 @@ class exception_wrapper final {
   static bool with_exception_(This& this_, Fn fn_);
 
  public:
+  static exception_wrapper from_exception_ptr(
+      std::exception_ptr const& eptr) noexcept;
+
   //! Default-constructs an empty `exception_wrapper`
   //! \post `type() == none()`
   exception_wrapper() noexcept {}
@@ -643,7 +644,7 @@ inline exception_wrapper try_and_catch_(F&& f) {
     return exception_wrapper(std::current_exception(), ex);
   }
 }
-} // detail
+} // namespace detail
 
 //! `try_and_catch` is a simple replacement for `try {} catch(){}`` that allows
 //! you to specify which derived exceptions you would like to catch and store in
@@ -684,7 +685,7 @@ template <typename... Exceptions, typename F>
 exception_wrapper try_and_catch(F&& fn) {
   return detail::try_and_catch_<F, Exceptions...>(std::forward<F>(fn));
 }
-} // folly
+} // namespace folly
 
 #include <folly/ExceptionWrapper-inl.h>