Commit fce8cf56 authored by Marshall Cline's avatar Marshall Cline Committed by Facebook Github Bot

FutureBase::assign() consumes its arg, so pass that arg via rvalue-ref

Summary:
future/semifuture move-assignment operators call this->assign(). The latter's arg was passed as an lvalue-ref. Result: now that arg is an rvalue-ref.

Note: I adjusted the assign() calling convention to avoid a forwarding ref. It would have been okay but it's easier to avoid a forwarding-ref than to explain why it happens to always be an rvalue-ref.

Reviewed By: yfeldblum

Differential Revision: D7831539

fbshipit-source-id: cf1c66cd498f768905ac3d21e39f693d7a652b39
parent 19c316ae
...@@ -161,9 +161,9 @@ FutureBase<T>::FutureBase(in_place_t, Args&&... args) ...@@ -161,9 +161,9 @@ FutureBase<T>::FutureBase(in_place_t, Args&&... args)
} }
template <class T> template <class T>
template <class FutureType> void FutureBase<T>::assign(FutureBase<T>&& other) noexcept {
void FutureBase<T>::assign(FutureType& other) noexcept { detach();
std::swap(core_, other.core_); core_ = exchange(other.core_, nullptr);
} }
template <class T> template <class T>
...@@ -662,14 +662,14 @@ SemiFuture<T>::SemiFuture(Future<T>&& other) noexcept ...@@ -662,14 +662,14 @@ SemiFuture<T>::SemiFuture(Future<T>&& other) noexcept
template <class T> template <class T>
SemiFuture<T>& SemiFuture<T>::operator=(SemiFuture<T>&& other) noexcept { SemiFuture<T>& SemiFuture<T>::operator=(SemiFuture<T>&& other) noexcept {
releaseDeferredExecutor(this->core_); releaseDeferredExecutor(this->core_);
this->assign(other); this->assign(std::move(other));
return *this; return *this;
} }
template <class T> template <class T>
SemiFuture<T>& SemiFuture<T>::operator=(Future<T>&& other) noexcept { SemiFuture<T>& SemiFuture<T>::operator=(Future<T>&& other) noexcept {
releaseDeferredExecutor(this->core_); releaseDeferredExecutor(this->core_);
this->assign(other); this->assign(std::move(other));
// SemiFuture should not have an executor on construction // SemiFuture should not have an executor on construction
if (this->core_) { if (this->core_) {
this->setExecutor(nullptr); this->setExecutor(nullptr);
...@@ -816,7 +816,7 @@ Future<T>::Future(Future<T>&& other) noexcept ...@@ -816,7 +816,7 @@ Future<T>::Future(Future<T>&& other) noexcept
template <class T> template <class T>
Future<T>& Future<T>::operator=(Future<T>&& other) noexcept { Future<T>& Future<T>::operator=(Future<T>&& other) noexcept {
this->assign(other); this->assign(std::move(other));
return *this; return *this;
} }
......
...@@ -197,8 +197,7 @@ class FutureBase { ...@@ -197,8 +197,7 @@ class FutureBase {
void throwIfInvalid() const; void throwIfInvalid() const;
template <class FutureType> void assign(FutureBase<T>&& other) noexcept;
void assign(FutureType&) noexcept;
Executor* getExecutor() const { Executor* getExecutor() const {
return getCore().getExecutor(); return getCore().getExecutor();
......
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