Commit efecbe5f authored by Hannes Roth's avatar Hannes Roth Committed by Noam Lerner

(Wangle) Clean up move constructors

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
parent f6da18f2
...@@ -33,12 +33,12 @@ namespace detail { ...@@ -33,12 +33,12 @@ namespace detail {
} }
template <class T> template <class T>
Future<T>::Future(Future<T>&& other) noexcept : core_(nullptr) { Future<T>::Future(Future<T>&& other) noexcept : core_(other.core_) {
*this = std::move(other); other.core_ = nullptr;
} }
template <class T> 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_); std::swap(core_, other.core_);
return *this; return *this;
} }
......
...@@ -193,7 +193,7 @@ class Future { ...@@ -193,7 +193,7 @@ class Future {
// movable // movable
Future(Future&&) noexcept; Future(Future&&) noexcept;
Future& operator=(Future&&); Future& operator=(Future&&) noexcept;
// makeFuture // makeFuture
template <class F = T> template <class F = T>
......
...@@ -29,12 +29,14 @@ Promise<T>::Promise() : retrieved_(false), core_(new detail::Core<T>()) ...@@ -29,12 +29,14 @@ Promise<T>::Promise() : retrieved_(false), core_(new detail::Core<T>())
{} {}
template <class T> template <class T>
Promise<T>::Promise(Promise<T>&& other) : core_(nullptr) { Promise<T>::Promise(Promise<T>&& other) noexcept
*this = std::move(other); : retrieved_(other.retrieved_), core_(other.core_) {
other.core_ = nullptr;
other.retrieved_ = false;
} }
template <class T> 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(core_, other.core_);
std::swap(retrieved_, other.retrieved_); std::swap(retrieved_, other.retrieved_);
return *this; return *this;
......
...@@ -36,8 +36,8 @@ public: ...@@ -36,8 +36,8 @@ public:
Promise& operator=(Promise const&) = delete; Promise& operator=(Promise const&) = delete;
// movable // movable
Promise(Promise<T>&&); Promise(Promise<T>&&) noexcept;
Promise& operator=(Promise<T>&&); Promise& operator=(Promise<T>&&) noexcept;
/** Return a Future tied to the shared core state. This can be called only /** Return a Future tied to the shared core state. This can be called only
once, thereafter Future already retrieved exception will be raised. */ once, thereafter Future already retrieved exception will be raised. */
......
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