From: Hannes Roth Date: Thu, 2 Apr 2015 04:31:29 +0000 (-0700) Subject: (Wangle) Swap order of Try and T matching X-Git-Tag: v0.33.0~6 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3ae1ec3c20ff7ec241ac20a1a89300128d08c1af;p=folly.git (Wangle) Swap order of Try and T matching Summary: See the test case and D1958860. I don't really know why I chose one over the other. This fixes a bug. So it's better? Test Plan: Run all the tests? Reviewed By: yfeldblum@fb.com Subscribers: folly-diffs@, jsedgwick, yfeldblum, chalfant, over FB internal diff: D1960740 Signature: t1:1960740:1427927644:25093b049a1519d7c869ee7043f3caced4cc971e --- diff --git a/folly/futures/Future.h b/folly/futures/Future.h index f507748d..18649726 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -99,15 +99,15 @@ struct callableResult { callableWith::value, detail::argResult, typename std::conditional< - callableWith&&>::value, - detail::argResult&&>, + callableWith::value, + detail::argResult, typename std::conditional< - callableWith&>::value, - detail::argResult&>, + callableWith::value, + detail::argResult, typename std::conditional< - callableWith::value, - detail::argResult, - detail::argResult>::type>::type>::type>::type Arg; + callableWith&&>::value, + detail::argResult&&>, + detail::argResult&>>::type>::type>::type>::type Arg; typedef isFuture ReturnsFuture; typedef Future Return; }; diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index 3da4dcfb..5a38c18b 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -1311,6 +1312,20 @@ TEST(Future, ImplicitConstructor) { //auto f2 = []() -> Future { }(); } +TEST(Future, thenDynamic) { + // folly::dynamic has a constructor that takes any T, this test makes + // sure that we call the then lambda with folly::dynamic and not + // Try because that then fails to compile + Promise p; + Future f = p.getFuture().then( + [](const folly::dynamic& d) { + return folly::dynamic(d.asInt() + 3); + } + ); + p.setValue(2); + EXPECT_EQ(f.get(), 5); +} + TEST(Future, via_then_get_was_racy) { ThreadExecutor x; std::unique_ptr val = folly::via(&x)