From f144d22401381441e36b4a96e4287806a971d554 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 10 Jan 2017 20:53:38 -0800 Subject: [PATCH] Slight simplification of exception_wrapper constructor Summary: [Folly] Slight simplification of `exception_wrapper` constructor. Reviewed By: ericniebler Differential Revision: D4391899 fbshipit-source-id: ddb066723bcd10abb0dbbaeab12b1e9be4f39acc --- folly/ExceptionWrapper.h | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index f839af7d..bd5bc119 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -111,19 +111,16 @@ class exception_wrapper { template using is_exception_ = std::is_base_of; - template - struct optimize; - public: exception_wrapper() = default; - // Implicitly construct an exception_wrapper from a qualifying exception. - // See the optimize struct for details. template < typename Ex, - typename = _t>>::value>>> + typename DEx = _t>, + typename = _t::value>>, + typename = decltype(DEx(std::forward(std::declval())))> /* implicit */ exception_wrapper(Ex&& exn) { - assign_sptr(std::make_shared<_t>>(std::forward(exn))); + assign_sptr(std::forward(exn)); } // The following two constructors are meant to emulate the behavior of @@ -238,17 +235,9 @@ class exception_wrapper { } private: - template - struct optimize { - static const bool value = - std::is_base_of::value && - std::is_copy_assignable::value && - !std::is_abstract::value; - }; - - template - void assign_sptr(std::shared_ptr sptr) { - this->item_ = std::move(sptr); + template + void assign_sptr(Args&&... args) { + this->item_ = std::make_shared(std::forward(args)...); this->throwfn_ = Thrower::doThrow; } @@ -348,10 +337,10 @@ class exception_wrapper { } }; -template +template exception_wrapper make_exception_wrapper(Args&&... args) { exception_wrapper ew; - ew.assign_sptr(std::make_shared(std::forward(args)...)); + ew.assign_sptr(std::forward(args)...); return ew; } -- 2.34.1