Skip to content

Commit 4813f78

Browse files
LeeHowesfacebook-github-bot
authored andcommittedJul 29, 2018
Modify thenTry to fail correctly with a parameterless lambda
Summary: Removes support for thenTry to accept a lambda with no parameter list and fail to compile with no arguments. Reviewed By: yfeldblum Differential Revision: D9011934 fbshipit-source-id: ec29b0c3d9475e7d2c566469b0ee333f0dc05738
1 parent 82fb08d commit 4813f78

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed
 

‎folly/futures/Future-inl.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,10 @@ template <class T>
10781078
template <typename F>
10791079
Future<typename futures::detail::tryCallableResult<T, F>::value_type>
10801080
Future<T>::thenTry(F&& func) && {
1081-
return std::move(*this).then(std::forward<F>(func));
1081+
return std::move(*this).then(
1082+
[f = std::forward<F>(func)](folly::Try<T>&& t) mutable {
1083+
return std::forward<F>(f)(std::move(t));
1084+
});
10821085
}
10831086

10841087
template <class T>

‎folly/futures/Future.h

+5
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,11 @@ class Future : private futures::detail::FutureBase<T> {
12321232
Future<typename futures::detail::tryCallableResult<T, F>::value_type> thenTry(
12331233
F&& func) &&;
12341234

1235+
template <typename R, typename... Args>
1236+
auto thenTry(R (&func)(Args...)) && {
1237+
return std::move(*this).thenTry(&func);
1238+
}
1239+
12351240
/// When this Future has completed, execute func which is a function that
12361241
/// can be called with `T&&` (often a lambda with parameter type
12371242
/// `auto&&` or `auto`).

‎folly/futures/test/FutureTest.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,8 @@ static folly::Future<std::string> doWorkStaticTry(Try<std::string>&& t) {
950950

951951
TEST(Future, thenTrythenValue) {
952952
auto f =
953-
makeFuture<std::string>("0")
954-
.thenTry([]() { return makeFuture<std::string>("1"); })
953+
makeFuture()
954+
.thenTry([](auto&&) { return makeFuture<std::string>("1"); })
955955
.thenTry(
956956
[](Try<std::string>&& t) { return makeFuture(t.value() + ";2"); })
957957
.thenTry([](const Try<std::string>&& t) {

0 commit comments

Comments
 (0)
Please sign in to comment.