Commit f144d224 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Slight simplification of exception_wrapper constructor

Summary: [Folly] Slight simplification of `exception_wrapper` constructor.

Reviewed By: ericniebler

Differential Revision: D4391899

fbshipit-source-id: ddb066723bcd10abb0dbbaeab12b1e9be4f39acc
parent 3a8c98ea
...@@ -111,19 +111,16 @@ class exception_wrapper { ...@@ -111,19 +111,16 @@ class exception_wrapper {
template <typename T> template <typename T>
using is_exception_ = std::is_base_of<std::exception, T>; using is_exception_ = std::is_base_of<std::exception, T>;
template <typename Ex>
struct optimize;
public: public:
exception_wrapper() = default; exception_wrapper() = default;
// Implicitly construct an exception_wrapper from a qualifying exception.
// See the optimize struct for details.
template < template <
typename Ex, typename Ex,
typename = _t<std::enable_if<optimize<_t<std::decay<Ex>>>::value>>> typename DEx = _t<std::decay<Ex>>,
typename = _t<std::enable_if<is_exception_<DEx>::value>>,
typename = decltype(DEx(std::forward<Ex>(std::declval<Ex&&>())))>
/* implicit */ exception_wrapper(Ex&& exn) { /* implicit */ exception_wrapper(Ex&& exn) {
assign_sptr(std::make_shared<_t<std::decay<Ex>>>(std::forward<Ex>(exn))); assign_sptr<DEx>(std::forward<Ex>(exn));
} }
// The following two constructors are meant to emulate the behavior of // The following two constructors are meant to emulate the behavior of
...@@ -238,17 +235,9 @@ class exception_wrapper { ...@@ -238,17 +235,9 @@ class exception_wrapper {
} }
private: private:
template <typename Ex> template <typename Ex, typename... Args>
struct optimize { void assign_sptr(Args&&... args) {
static const bool value = this->item_ = std::make_shared<Ex>(std::forward<Args>(args)...);
std::is_base_of<std::exception, Ex>::value &&
std::is_copy_assignable<Ex>::value &&
!std::is_abstract<Ex>::value;
};
template <typename Ex>
void assign_sptr(std::shared_ptr<Ex> sptr) {
this->item_ = std::move(sptr);
this->throwfn_ = Thrower<Ex>::doThrow; this->throwfn_ = Thrower<Ex>::doThrow;
} }
...@@ -348,10 +337,10 @@ class exception_wrapper { ...@@ -348,10 +337,10 @@ class exception_wrapper {
} }
}; };
template <class T, class... Args> template <class Ex, class... Args>
exception_wrapper make_exception_wrapper(Args&&... args) { exception_wrapper make_exception_wrapper(Args&&... args) {
exception_wrapper ew; exception_wrapper ew;
ew.assign_sptr(std::make_shared<T>(std::forward<Args>(args)...)); ew.assign_sptr<Ex>(std::forward<Args>(args)...);
return ew; return ew;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment