Revert: (Wangle) Clean up move constructors
authorHannes Roth <hannesr@fb.com>
Thu, 19 Feb 2015 23:10:49 +0000 (15:10 -0800)
committerAlecs King <int@fb.com>
Tue, 3 Mar 2015 03:25:34 +0000 (19:25 -0800)
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
folly/futures/Future.h
folly/futures/Promise-inl.h
folly/futures/Promise.h

index 516eb502521cb3fec28e82dfca9b286221c0366e..a8454155f518c25a82173ed9a49bf595ef9b452e 100644 (file)
@@ -32,14 +32,13 @@ namespace detail {
 }
 
 template <class T>
-Future<T>::Future(Future<T>&& other) noexcept : core_(other.core_) {
-  other.core_ = nullptr;
+Future<T>::Future(Future<T>&& other) noexcept : core_(nullptr) {
+  *this = std::move(other);
 }
 
 template <class T>
-Future<T>& Future<T>::operator=(Future<T>&& other) noexcept {
-  core_ = other.core_;
-  other.core_ = nullptr;
+Future<T>& Future<T>::operator=(Future<T>&& other) {
+  std::swap(core_, other.core_);
   return *this;
 }
 
index c351416bb8b96e590e11cbc258111f4b0bf3dff3..1ac7e652d19eb426fb0749cf62bb5b7db5e4c0a5 100644 (file)
@@ -192,7 +192,7 @@ class Future {
 
   // movable
   Future(Future&&) noexcept;
-  Future& operator=(Future&&) noexcept;
+  Future& operator=(Future&&);
 
   // makeFuture
   template <class F = T>
index 1f4b7aa39f0137bda8911b0135f4ae96bbb75176..b347486a4faa0d10999e3d852462bb98fbb68985 100644 (file)
@@ -29,16 +29,14 @@ Promise<T>::Promise() : retrieved_(false), core_(new detail::Core<T>())
 {}
 
 template <class T>
-Promise<T>::Promise(Promise<T>&& other) noexcept
-    : retrieved_(other.retrieved_), core_(other.core_) {
-  other.core_ = nullptr;
+Promise<T>::Promise(Promise<T>&& other) : core_(nullptr) {
+  *this = std::move(other);
 }
 
 template <class T>
-Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept {
-  retrieved_ = other.retrieved_;
-  core_ = other.core_;
-  other.core_ = nullptr;
+Promise<T>& Promise<T>::operator=(Promise<T>&& other) {
+  std::swap(core_, other.core_);
+  std::swap(retrieved_, other.retrieved_);
   return *this;
 }
 
index a223db0b4a771fe7bd5e028c089e7b3123d327dc..1412577ff58ee79f04281b2fed82be34b519d0f3 100644 (file)
@@ -36,8 +36,8 @@ public:
   Promise& operator=(Promise const&) = delete;
 
   // movable
-  Promise(Promise<T>&&) noexcept;
-  Promise& operator=(Promise<T>&&) noexcept;
+  Promise(Promise<T>&&);
+  Promise& operator=(Promise<T>&&);
 
   /** Return a Future tied to the shared core state. This can be called only
     once, thereafter Future already retrieved exception will be raised. */