X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FExceptionWrapper-inl.h;h=287275aec9ed73ab53bfba9fffb8f80a42b34de7;hb=60b2478a8e299bbae257a5fe69837696c0950ee5;hp=d0062bcacd0c570a9622ef7007c6041e8950f404;hpb=d2efd8104d4191f67140ecdbd5343ba05552f083;p=folly.git diff --git a/folly/ExceptionWrapper-inl.h b/folly/ExceptionWrapper-inl.h index d0062bca..287275ae 100644 --- a/folly/ExceptionWrapper-inl.h +++ b/folly/ExceptionWrapper-inl.h @@ -287,32 +287,38 @@ inline exception_wrapper::exception_wrapper(std::exception_ptr ptr, Ex& ex) assert(eptr_.ptr_); } +namespace exception_wrapper_detail { +template +Ex&& dont_slice(Ex&& ex) { + assert(typeid(ex) == typeid(_t>) || + !"Dynamic and static exception types don't match. Exception would " + "be sliced when storing in exception_wrapper."); + return std::forward(ex); +} +} + template < class Ex, class Ex_, FOLLY_REQUIRES_DEF( Conjunction< exception_wrapper::IsStdException, - exception_wrapper::IsRegularExceptionType>())> + exception_wrapper::IsRegularExceptionType>::value)> inline exception_wrapper::exception_wrapper(Ex&& ex) - : exception_wrapper{std::forward(ex), PlacementOf{}} { - // Don't slice!!! - assert(typeid(ex) == typeid(Ex_) || - !"Dynamic and static exception types don't match. Exception would " - "be sliced when storing in exception_wrapper."); + : exception_wrapper{ + exception_wrapper_detail::dont_slice(std::forward(ex)), + PlacementOf{}} { } template < class Ex, class Ex_, FOLLY_REQUIRES_DEF( - exception_wrapper::IsRegularExceptionType())> + exception_wrapper::IsRegularExceptionType::value)> inline exception_wrapper::exception_wrapper(in_place_t, Ex&& ex) - : exception_wrapper{std::forward(ex), PlacementOf{}} { - // Don't slice!!! - assert(typeid(ex) == typeid(Ex_) || - !"Dynamic and static exception types don't match. Exception would " - "be sliced when storing in exception_wrapper."); + : exception_wrapper{ + exception_wrapper_detail::dont_slice(std::forward(ex)), + PlacementOf{}} { } inline void exception_wrapper::swap(exception_wrapper& that) noexcept { @@ -344,6 +350,20 @@ inline std::exception const* exception_wrapper::get_exception() const noexcept { return vptr_->get_exception_(this); } +template +inline Ex* exception_wrapper::get_exception() noexcept { + Ex* object{nullptr}; + with_exception([&](Ex& ex) { object = &ex; }); + return object; +} + +template +inline Ex const* exception_wrapper::get_exception() const noexcept { + Ex const* object{nullptr}; + with_exception([&](Ex const& ex) { object = &ex; }); + return object; +} + inline std::exception_ptr const& exception_wrapper::to_exception_ptr() noexcept { // Computing an exception_ptr is expensive so cache the result.