From 32623e8e6c4f28c2d7c10e813b97bed063686c1f Mon Sep 17 00:00:00 2001 From: Sven Over Date: Tue, 3 May 2016 14:27:37 -0700 Subject: [PATCH] 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 --- folly/futures/Future-inl.h | 2 +- folly/futures/test/ViaTest.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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)); +} -- 2.34.1