Commit 8d0571ca authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

CodeMod: future-then-continuation-lvalue-ref

Summary:
CodeMod: `future-then-continuation-lvalue-ref`.

```
buck run mode/opt foundation/clangr:clangr_coordinator -- run foundation/clang/codemods:future-then-continuation-lvalue-ref --dev -p 7 --num-workers=200
```

There is no need to support continuations taking non-const lvalue-ref params; callers can get exactly the same semantics with non-const rvalue-ref params instead. Thsi codemod preserves semantics. Many of these cases could do just as well taking by value, but this codemod preserves semantics.

Reviewed By: Orvid

Differential Revision: D8166008

fbshipit-source-id: 84b635cccce24b6485ffb5b24b98f10422b9a517
parent df028149
......@@ -1507,22 +1507,20 @@ Future<T> reduce(It first, It last, T&& initial, F&& func) {
auto sfunc = std::make_shared<F>(std::move(func));
auto f = first->then([minitial = std::forward<T>(initial),
sfunc](Try<ItT>& head) mutable {
sfunc](Try<ItT>&& head) mutable {
return (*sfunc)(
std::forward<T>(minitial), head.template get<IsTry::value, Arg&&>());
});
for (++first; first != last; ++first) {
f = collectAllSemiFuture(f, *first).toUnsafeFuture().then([sfunc](
std::tuple<
Try<T>,
Try<ItT>>&
t) {
return (*sfunc)(std::move(std::get<0>(t).value()),
// Either return a ItT&& or a Try<ItT>&& depending
// on the type of the argument of func.
std::get<1>(t).template get<IsTry::value, Arg&&>());
});
f = collectAllSemiFuture(f, *first).toUnsafeFuture().then(
[sfunc](std::tuple<Try<T>, Try<ItT>>&& t) {
return (*sfunc)(
std::move(std::get<0>(t).value()),
// Either return a ItT&& or a Try<ItT>&& depending
// on the type of the argument of func.
std::get<1>(t).template get<IsTry::value, Arg&&>());
});
}
return f;
......@@ -1600,10 +1598,8 @@ window(Executor* executor, Collection input, F func, size_t n) {
template <class T>
template <class I, class F>
Future<I> Future<T>::reduce(I&& initial, F&& func) {
return then([
minitial = std::forward<I>(initial),
mfunc = std::forward<F>(func)
](T& vals) mutable {
return then([minitial = std::forward<I>(initial),
mfunc = std::forward<F>(func)](T&& vals) mutable {
auto ret = std::move(minitial);
for (auto& val : vals) {
ret = mfunc(std::move(ret), std::move(val));
......
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