Use simpler tags for ctor dispatch in exception_wrapper
authorYedidya Feldblum <yfeldblum@fb.com>
Thu, 7 Dec 2017 20:38:57 +0000 (12:38 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 7 Dec 2017 20:51:13 +0000 (12:51 -0800)
Summary:
[Folly] Use simpler tags for ctor dispatch in `exception_wrapper`.

The tags do not need to be `std::integral_constant`, but can just be arbitrary empty types.

Also format the usage sites of the tags.

Reviewed By: ericniebler

Differential Revision: D6506417

fbshipit-source-id: 377359086d94fc1a8bf8eebf6f8b058ff544829f

folly/ExceptionWrapper-inl.h
folly/ExceptionWrapper.h

index 790b24c..6e4fe11 100644 (file)
@@ -281,12 +281,18 @@ inline exception_wrapper exception_wrapper::SharedPtr::get_exception_ptr_(
 }
 
 template <class Ex, typename... As>
-inline exception_wrapper::exception_wrapper(OnHeapTag, in_place_type_t<Ex>, As&&... as)
+inline exception_wrapper::exception_wrapper(
+    OnHeapTag,
+    in_place_type_t<Ex>,
+    As&&... as)
     : sptr_{std::make_shared<SharedPtr::Impl<Ex>>(std::forward<As>(as)...)},
       vptr_(&SharedPtr::ops_) {}
 
 template <class Ex, typename... As>
-inline exception_wrapper::exception_wrapper(InSituTag, in_place_type_t<Ex>, As&&... as)
+inline exception_wrapper::exception_wrapper(
+    InSituTag,
+    in_place_type_t<Ex>,
+    As&&... as)
     : buff_{in_place_type<Ex>, std::forward<As>(as)...},
       vptr_(&InPlace<Ex>::ops_) {}
 
index 0d02871..36913d8 100644 (file)
@@ -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);