(Wangle) Clean up move constructors
authorHannes Roth <hannesr@fb.com>
Wed, 18 Mar 2015 17:29:19 +0000 (10:29 -0700)
committerNoam Lerner <noamler@fb.com>
Wed, 25 Mar 2015 22:33:27 +0000 (15:33 -0700)
Summary: I thought this might fix #6120972. But it doesn't. Still a bit of a cleanup in my opinion.

Test Plan: Run all the tests?

Reviewed By: hans@fb.com

Subscribers: trunkagent, folly-diffs@, jsedgwick, yfeldblum

FB internal diff: D1907259

Signature: t1:1907259:1426613567:9e33fe7e9e8a36ba006d4aee604086a56f128893

folly/futures/Future-inl.h
folly/futures/Future.h
folly/futures/Promise-inl.h
folly/futures/Promise.h

index 077a633e9bd8d13146031cf2d72b175094d879cf..2e942303e2b4b359f8bcc4c109470b3152be3010 100644 (file)
@@ -33,12 +33,12 @@ namespace detail {
 }
 
 template <class T>
-Future<T>::Future(Future<T>&& other) noexcept : core_(nullptr) {
-  *this = std::move(other);
+Future<T>::Future(Future<T>&& other) noexcept : core_(other.core_) {
+  other.core_ = nullptr;
 }
 
 template <class T>
-Future<T>& Future<T>::operator=(Future<T>&& other) {
+Future<T>& Future<T>::operator=(Future<T>&& other) noexcept {
   std::swap(core_, other.core_);
   return *this;
 }
index 10bdc45ae94df80e63f752e25b0f02aca6750ce7..38b3072ef5ea8dc992007509b878e56c521edda5 100644 (file)
@@ -193,7 +193,7 @@ class Future {
 
   // movable
   Future(Future&&) noexcept;
-  Future& operator=(Future&&);
+  Future& operator=(Future&&) noexcept;
 
   // makeFuture
   template <class F = T>
index f38ee60dfd59f9dd7381a0d0fb2621327a2a4387..b57e952f93a4161911519828b8d6382a26fe8674 100644 (file)
@@ -29,12 +29,14 @@ Promise<T>::Promise() : retrieved_(false), core_(new detail::Core<T>())
 {}
 
 template <class T>
-Promise<T>::Promise(Promise<T>&& other) : core_(nullptr) {
-  *this = std::move(other);
+Promise<T>::Promise(Promise<T>&& other) noexcept
+    : retrieved_(other.retrieved_), core_(other.core_) {
+  other.core_ = nullptr;
+  other.retrieved_ = false;
 }
 
 template <class T>
-Promise<T>& Promise<T>::operator=(Promise<T>&& other) {
+Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept {
   std::swap(core_, other.core_);
   std::swap(retrieved_, other.retrieved_);
   return *this;
index 7d1eafc086092563c2d6c5df624ec208e50ca99f..a38d6f1c82604401f104b215f65f8e4c14ea8a96 100644 (file)
@@ -36,8 +36,8 @@ public:
   Promise& operator=(Promise const&) = delete;
 
   // movable
-  Promise(Promise<T>&&);
-  Promise& operator=(Promise<T>&&);
+  Promise(Promise<T>&&) noexcept;
+  Promise& operator=(Promise<T>&&) noexcept;
 
   /** Return a Future tied to the shared core state. This can be called only
     once, thereafter Future already retrieved exception will be raised. */