Let via take a functor by universal reference
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 4 May 2016 04:32:23 +0000 (21:32 -0700)
committerFacebook Github Bot 3 <facebook-github-bot-3-bot@fb.com>
Wed, 4 May 2016 04:35:24 +0000 (21:35 -0700)
Summary:
[Folly] Let `via` take a functor by universal reference.

And perfect-forward the functor to the call to `then`.

Reviewed By: fugalh

Differential Revision: D3255684

fb-gh-sync-id: 1b46a70fb9de88d21d785c0ce4d9dd3078829f13
fbshipit-source-id: 1b46a70fb9de88d21d785c0ce4d9dd3078829f13

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

index ed3aa434ad1ac5da645709b82d5d4d8c3ec65714..aebe58b652182fbf6380c38ed06071e7be0ebc09 100644 (file)
@@ -444,11 +444,11 @@ inline Future<T> Future<T>::via(Executor* executor, int8_t priority) & {
 }
 
 template <class Func>
-auto via(Executor* x, Func func)
+auto via(Executor* x, Func&& func)
   -> Future<typename isFuture<decltype(func())>::Inner>
 {
   // TODO make this actually more performant. :-P #7260175
-  return via(x).then(std::move(func));
+  return via(x).then(std::forward<Func>(func));
 }
 
 template <class T>
index bcfd8ba358d6ce03232646b6545a1f1c1bc42fd8..75f925374bd22521b2a5c8fc22e6113d823f1d48 100644 (file)
@@ -147,7 +147,7 @@ inline Future<Unit> via(
 /// This is semantically equivalent to via(executor).then(func), but
 /// easier to read and slightly more efficient.
 template <class Func>
-auto via(Executor*, Func func)
+auto via(Executor*, Func&& func)
   -> Future<typename isFuture<decltype(func())>::Inner>;
 
 /** When all the input Futures complete, the returned Future will complete.