From 5e32096ce48bc300b14e95b11f5f09df7e3e5b13 Mon Sep 17 00:00:00 2001 From: Hannes Roth Date: Thu, 19 Feb 2015 15:10:49 -0800 Subject: [PATCH] Revert: (Wangle) Clean up move constructors Summary: This reverts commit 1e407b48d379a41f32e7a980285dbdf4dadb2e33. Test Plan: revert-hammer Reviewed By: yitingli@fb.com Subscribers: folly-diffs@, jsedgwick, yfeldblum FB internal diff: D1858994 Signature: t1:1858994:1424386588:5c4608ecbe1f9ab1108ac12e506b157b54d0078b --- folly/futures/Future-inl.h | 9 ++++----- folly/futures/Future.h | 2 +- folly/futures/Promise-inl.h | 12 +++++------- folly/futures/Promise.h | 4 ++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 516eb502..a8454155 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -32,14 +32,13 @@ namespace detail { } template -Future::Future(Future&& other) noexcept : core_(other.core_) { - other.core_ = nullptr; +Future::Future(Future&& other) noexcept : core_(nullptr) { + *this = std::move(other); } template -Future& Future::operator=(Future&& other) noexcept { - core_ = other.core_; - other.core_ = nullptr; +Future& Future::operator=(Future&& other) { + std::swap(core_, other.core_); return *this; } diff --git a/folly/futures/Future.h b/folly/futures/Future.h index c351416b..1ac7e652 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -192,7 +192,7 @@ class Future { // movable Future(Future&&) noexcept; - Future& operator=(Future&&) noexcept; + Future& operator=(Future&&); // makeFuture template diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index 1f4b7aa3..b347486a 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -29,16 +29,14 @@ Promise::Promise() : retrieved_(false), core_(new detail::Core()) {} template -Promise::Promise(Promise&& other) noexcept - : retrieved_(other.retrieved_), core_(other.core_) { - other.core_ = nullptr; +Promise::Promise(Promise&& other) : core_(nullptr) { + *this = std::move(other); } template -Promise& Promise::operator=(Promise&& other) noexcept { - retrieved_ = other.retrieved_; - core_ = other.core_; - other.core_ = nullptr; +Promise& Promise::operator=(Promise&& other) { + std::swap(core_, other.core_); + std::swap(retrieved_, other.retrieved_); return *this; } diff --git a/folly/futures/Promise.h b/folly/futures/Promise.h index a223db0b..1412577f 100644 --- a/folly/futures/Promise.h +++ b/folly/futures/Promise.h @@ -36,8 +36,8 @@ public: Promise& operator=(Promise const&) = delete; // movable - Promise(Promise&&) noexcept; - Promise& operator=(Promise&&) noexcept; + Promise(Promise&&); + Promise& operator=(Promise&&); /** Return a Future tied to the shared core state. This can be called only once, thereafter Future already retrieved exception will be raised. */ -- 2.34.1