From: Sven Over Date: Tue, 3 May 2016 21:27:37 +0000 (-0700) Subject: fix passing move-only types to via(Executor*, Func) X-Git-Tag: 2016.07.26~291 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=32623e8e6c4f28c2d7c10e813b97bed063686c1f;p=folly.git fix passing move-only types to via(Executor*, Func) 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 --- diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 1f107f91..ed3aa434 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -448,7 +448,7 @@ auto via(Executor* x, Func func) -> Future::Inner> { // TODO make this actually more performant. :-P #7260175 - return via(x).then(func); + return via(x).then(std::move(func)); } template diff --git a/folly/futures/test/ViaTest.cpp b/folly/futures/test/ViaTest.cpp index bffd0519..78231873 100644 --- a/folly/futures/test/ViaTest.cpp +++ b/folly/futures/test/ViaTest.cpp @@ -495,3 +495,10 @@ TEST(ViaFunc, isSticky) { x.run(); EXPECT_EQ(2, count); } + +TEST(ViaFunc, moveOnly) { + ManualExecutor x; + auto intp = folly::make_unique(42); + + EXPECT_EQ(42, via(&x, [intp = std::move(intp)] { return *intp; }).getVia(&x)); +}