assert(eptr_.ptr_);
}
+namespace exception_wrapper_detail {
+template <class Ex>
+Ex&& dont_slice(Ex&& ex) {
+ assert(typeid(ex) == typeid(_t<std::decay<Ex>>) ||
+ !"Dynamic and static exception types don't match. Exception would "
+ "be sliced when storing in exception_wrapper.");
+ return std::forward<Ex>(ex);
+}
+}
+
template <
class Ex,
class Ex_,
FOLLY_REQUIRES_DEF(
Conjunction<
exception_wrapper::IsStdException<Ex_>,
- exception_wrapper::IsRegularExceptionType<Ex_>>())>
+ exception_wrapper::IsRegularExceptionType<Ex_>>::value)>
inline exception_wrapper::exception_wrapper(Ex&& ex)
- : exception_wrapper{std::forward<Ex>(ex), PlacementOf<Ex_>{}} {
- // 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>(ex)),
+ PlacementOf<Ex_>{}} {
}
template <
class Ex,
class Ex_,
FOLLY_REQUIRES_DEF(
- exception_wrapper::IsRegularExceptionType<Ex_>())>
+ exception_wrapper::IsRegularExceptionType<Ex_>::value)>
inline exception_wrapper::exception_wrapper(in_place_t, Ex&& ex)
- : exception_wrapper{std::forward<Ex>(ex), PlacementOf<Ex_>{}} {
- // 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>(ex)),
+ PlacementOf<Ex_>{}} {
}
inline void exception_wrapper::swap(exception_wrapper& that) noexcept {
return vptr_->get_exception_(this);
}
+template <typename Ex>
+inline Ex* exception_wrapper::get_object() noexcept {
+ Ex* object{nullptr};
+ with_exception([&](Ex& ex) { object = &ex; });
+ return object;
+}
+
+template <typename Ex>
+inline Ex const* exception_wrapper::get_object() 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.