Future<Unit> global fixup
authorHans Fugal <fugalh@fb.com>
Wed, 1 Jul 2015 22:42:50 +0000 (15:42 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 1 Jul 2015 23:24:55 +0000 (16:24 -0700)
Summary: This is three codemods:

* `(folly::(Future|Promise|Try))<void>` -> `\1<folly::Unit>`
* `(Future|Promise|Try)<void>` -> `\1<Unit>`
* add `using folly::Unit` statements where needed

Then
* undo false positives in javascript files and fibers::Promise

cf D2201259, which this will land with

Reviewed By: @djwatson

Differential Revision: D2201801

folly/futures/Future-inl.h
folly/futures/helpers.h

index 0595310a4cc41024268d72426037e00bd8991cae..380b006925fcd97647cde9e0cac4565be729d2a6 100644 (file)
@@ -470,27 +470,15 @@ Future<Unit> makeFuture() {
   return makeFuture(Unit{});
 }
 
-// XXX why is the dual necessary here? Can't we just use perfect forwarding
-// and capture func by reference always?
 template <class F>
-auto makeFutureWith(
-    F&& func,
-    typename std::enable_if<!std::is_reference<F>::value, bool>::type sdf)
+auto makeFutureWith(F&& func)
     -> Future<typename Unit::Lift<decltype(func())>::type> {
   using LiftedResult = typename Unit::Lift<decltype(func())>::type;
-  return makeFuture<LiftedResult>(makeTryWith([&func]() {
-    return (func)();
+  return makeFuture<LiftedResult>(makeTryWith([&func]() mutable {
+    return func();
   }));
 }
 
-template <class F>
-auto makeFutureWith(F const& func)
-    -> Future<typename Unit::Lift<decltype(func())>::type> {
-  F copy = func;
-  using LiftedResult = typename Unit::Lift<decltype(func())>::type;
-  return makeFuture<LiftedResult>(makeTryWith(std::move(copy)));
-}
-
 template <class T>
 Future<T> makeFuture(std::exception_ptr const& e) {
   return makeFuture(Try<T>(e));
index 0d0b881cf5829268919edf3c71a82a5096349721..3b762732189172297b3c216bf48f91e3beae0052 100644 (file)
@@ -77,13 +77,7 @@ Future<Unit> makeFuture();
 /** Make a completed Future by executing a function. If the function throws
   we capture the exception, otherwise we capture the result. */
 template <class F>
-auto makeFutureWith(
-    F&& func,
-    typename std::enable_if<!std::is_reference<F>::value, bool>::type sdf)
-    -> Future<typename Unit::Lift<decltype(func())>::type>;
-
-template <class F>
-auto makeFutureWith(F const& func)
+auto makeFutureWith(F&& func)
     -> Future<typename Unit::Lift<decltype(func())>::type>;
 
 /// Make a failed Future from an exception_ptr.