From: Yedidya Feldblum Date: Thu, 7 Dec 2017 20:38:57 +0000 (-0800) Subject: Use simpler tags for ctor dispatch in exception_wrapper X-Git-Tag: v2017.12.11.00~13 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=a335700fba3a818043d53de320711dc97b680894 Use simpler tags for ctor dispatch in exception_wrapper 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 --- diff --git a/folly/ExceptionWrapper-inl.h b/folly/ExceptionWrapper-inl.h index 790b24ca..6e4fe114 100644 --- a/folly/ExceptionWrapper-inl.h +++ b/folly/ExceptionWrapper-inl.h @@ -281,12 +281,18 @@ inline exception_wrapper exception_wrapper::SharedPtr::get_exception_ptr_( } template -inline exception_wrapper::exception_wrapper(OnHeapTag, in_place_type_t, As&&... as) +inline exception_wrapper::exception_wrapper( + OnHeapTag, + in_place_type_t, + As&&... as) : sptr_{std::make_shared>(std::forward(as)...)}, vptr_(&SharedPtr::ops_) {} template -inline exception_wrapper::exception_wrapper(InSituTag, in_place_type_t, As&&... as) +inline exception_wrapper::exception_wrapper( + InSituTag, + in_place_type_t, + As&&... as) : buff_{in_place_type, std::forward(as)...}, vptr_(&InPlace::ops_) {} diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index 0d028714..36913d85 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -235,18 +235,16 @@ class exception_wrapper final { Ex const& as() const noexcept; }; - enum class Placement { kInSitu, kOnHeap }; + struct InSituTag {}; + struct OnHeapTag {}; + template - using PlacementOf = std::integral_constant< - Placement, + using PlacementOf = _t())) - ? Placement::kInSitu - : Placement::kOnHeap>; - - using InSituTag = std::integral_constant; - using OnHeapTag = std::integral_constant; + alignof(T) <= alignof(Buffer::Storage) && + noexcept(T(std::declval())), + InSituTag, + OnHeapTag>>; static std::exception const* as_exception_or_null_(std::exception const& ex); static std::exception const* as_exception_or_null_(AnyException);