Commit c7d609d4 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Add exception_wrapper::from_exception_ptr taking by &&

Summary: [Folly] Add `exception_wrapper::from_exception_ptr` taking by `&&`, permitting callers to move, since `std::exception_ptr` copy is expensive and `std::rethrow_exception` takes by value.

Reviewed By: ericniebler, markisaa

Differential Revision: D23016839

fbshipit-source-id: c07695fef0828a50426fe4e2b40fae9582c7ffd9
parent ebc1ae68
......@@ -63,11 +63,16 @@ std::exception const* get_std_exception_(std::exception_ptr eptr) noexcept {
exception_wrapper exception_wrapper::from_exception_ptr(
std::exception_ptr const& ptr) noexcept {
return from_exception_ptr(folly::copy(ptr));
}
exception_wrapper exception_wrapper::from_exception_ptr(
std::exception_ptr&& ptr) noexcept {
if (!ptr) {
return exception_wrapper();
}
try {
std::rethrow_exception(ptr);
std::rethrow_exception(std::move(ptr));
} catch (std::exception& e) {
return exception_wrapper(std::current_exception(), e);
} catch (...) {
......
......@@ -379,6 +379,8 @@ class exception_wrapper final {
public:
static exception_wrapper from_exception_ptr(
std::exception_ptr const& eptr) noexcept;
static exception_wrapper from_exception_ptr(
std::exception_ptr&& eptr) noexcept;
//! Default-constructs an empty `exception_wrapper`
//! \post `type() == none()`
......
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