fix passing move-only types to via(Executor*, Func)
authorSven Over <over@fb.com>
Tue, 3 May 2016 21:27:37 +0000 (14:27 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Tue, 3 May 2016 21:35:32 +0000 (14:35 -0700)
Summary: This diff fixes a problem with passing move-only types to folly::via.

Reviewed By: ericniebler

Differential Revision: D3254906

fb-gh-sync-id: 8a9c703a8db0ccf20b9fb4fe9b80ad6cdcb3e388
fbshipit-source-id: 8a9c703a8db0ccf20b9fb4fe9b80ad6cdcb3e388

folly/futures/Future-inl.h
folly/futures/test/ViaTest.cpp

index 1f107f91ddb54fd921baf3904940260743f87445..ed3aa434ad1ac5da645709b82d5d4d8c3ec65714 100644 (file)
@@ -448,7 +448,7 @@ auto via(Executor* x, Func func)
   -> Future<typename isFuture<decltype(func())>::Inner>
 {
   // TODO make this actually more performant. :-P #7260175
-  return via(x).then(func);
+  return via(x).then(std::move(func));
 }
 
 template <class T>
index bffd0519922f6649fd4e9ef64319bfeef16a836c..78231873d26213c4cfd438db62687260626c544d 100644 (file)
@@ -495,3 +495,10 @@ TEST(ViaFunc, isSticky) {
   x.run();
   EXPECT_EQ(2, count);
 }
+
+TEST(ViaFunc, moveOnly) {
+  ManualExecutor x;
+  auto intp = folly::make_unique<int>(42);
+
+  EXPECT_EQ(42, via(&x, [intp = std::move(intp)] { return *intp; }).getVia(&x));
+}