Commit 0fd618d4 authored by Hannes Roth's avatar Hannes Roth Committed by Alecs King

(Wangle) Clean up move constructors

Summary:
These were doing more assignments than necessary.
1) We don't need to set `core_` to `nullptr` and then immediately
overwrite it with `other.core_`.
2) Don't need to swap the booleans (this was actually an unitialized
memory access).

Test Plan: Ran all the tests.

Reviewed By: hans@fb.com

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

FB internal diff: D1852386

Signature: t1:1852386:1424375154:25997209e76ccd16169125597e868932a5143ffb
parent 37dd79a6
...@@ -32,13 +32,14 @@ namespace detail { ...@@ -32,13 +32,14 @@ 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_); core_ = other.core_;
other.core_ = nullptr;
return *this; return *this;
} }
......
...@@ -192,7 +192,7 @@ class Future { ...@@ -192,7 +192,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,14 +29,16 @@ Promise<T>::Promise() : retrieved_(false), core_(new detail::Core<T>()) ...@@ -29,14 +29,16 @@ 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;
} }
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_); retrieved_ = other.retrieved_;
std::swap(retrieved_, other.retrieved_); core_ = other.core_;
other.core_ = nullptr;
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