Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #229 #232

Merged
merged 1 commit into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stlab/concurrency/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#endif

#ifndef STLAB_CPP_VERSION
#define STLAB_CPP_VERSION 14
#define STLAB_CPP_VERSION 17
#endif

#ifndef STLAB_FUTURE_COROUTINES
Expand Down
26 changes: 14 additions & 12 deletions stlab/concurrency/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,16 +1683,18 @@ struct value_<T, enable_if_copyable<T>> {

template <typename F, typename... Args>
static void set(shared_base<future<void>>& sb, F& f, Args&&... args) {
sb._result = f(std::forward<Args>(args)...)
.recover([_p = sb.shared_from_this()](future<void> f) {
if (f.error()) {
_p->_error = std::move(*f.error());
value_::proceed(*_p);
throw future_error(future_error_codes::reduction_failed);
}
return;
})
.then([_p = sb.shared_from_this()]() { proceed(*_p); });
sb._result = f(std::forward<Args>(args)...);
sb._reduction_helper.value =
(*sb._result)
.recover([_p = sb.shared_from_this()](future<void> f) {
if (f.error()) {
_p->_error = std::move(*f.error());
value_::proceed(*_p);
throw future_error(future_error_codes::reduction_failed);
}
return;
})
.then([_p = sb.shared_from_this()]() { proceed(*_p); });
}
};

Expand Down Expand Up @@ -1810,13 +1812,13 @@ auto shared_base<T, enable_if_copyable<T>>::reduce(future<future<R>>&& r) -> fut

template <typename T>
auto shared_base<T, enable_if_not_copyable<T>>::reduce(future<future<void>>&& r) -> future<void> {
return std::move(r).then([](auto&&){});
return std::move(r).then([](auto){});
}

template <typename T>
template <typename R>
auto shared_base<T, enable_if_not_copyable<T>>::reduce(future<future<R>>&& r) -> future<R> {
return std::move(r).then([](auto&& f) { return *std::forward<future<R>>(f).get_try(); });
return std::move(r).then([](auto&& f) { return *std::move(f).get_try(); });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FelixPetriconi - can you speak a little bit to why you made this change? I would have thought the correct line here would be std::forward<decltype(f)>(f)... why is a move correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. I was looking at the signature from the reduce function and there it is an rvalue reference, that should be moved. But here, as you correctly have noticed, we are in a forwarding reference and your code would be the general solution to this. I will fix this now.

}

/**************************************************************************************************/
Expand Down