From d78429749bc315b744e1c7ae5f0969fbdf31ca3d Mon Sep 17 00:00:00 2001 From: Sven Over Date: Sat, 23 Apr 2016 08:07:25 -0700 Subject: [PATCH] use forward instead of move for universal references Summary:When dealing with universal references, std::move will move from objects that are passed as lvalue references. Instead std::forward should be used, which only moves from an object if it's passed as rvalue reference. Reviewed By: yfeldblum Differential Revision: D3200402 fb-gh-sync-id: 14be071e8498dd64cb8b2583c0cc2dd383bfebb8 fbshipit-source-id: 14be071e8498dd64cb8b2583c0cc2dd383bfebb8 --- folly/Conv.h | 2 +- folly/Subprocess.h | 2 +- folly/futures/Future.h | 2 +- folly/test/ApplyTupleTest.cpp | 4 ++-- folly/test/MPMCQueueTest.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/folly/Conv.h b/folly/Conv.h index ac2f5f2b..79276ca4 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -78,7 +78,7 @@ to(const Src & value) { template typename std::enable_if::value, Tgt>::type to(Src && value) { - return std::move(value); + return std::forward(value); } /******************************************************************************* diff --git a/folly/Subprocess.h b/folly/Subprocess.h index e922ee0d..7598ee46 100644 --- a/folly/Subprocess.h +++ b/folly/Subprocess.h @@ -662,7 +662,7 @@ class Subprocess { uint64_t maxLineLength = 0, // No line length limit by default char delimiter = '\n', uint64_t bufSize = 1024 - ) : fdLineCb_(std::move(fdLineCb)), + ) : fdLineCb_(std::forward(fdLineCb)), maxLineLength_(maxLineLength), delimiter_(delimiter), bufSize_(bufSize) {} diff --git a/folly/futures/Future.h b/folly/futures/Future.h index 49ff679a..990f2990 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -331,7 +331,7 @@ class Future { template void raise(E&& exception) { raise(make_exception_wrapper::type>( - std::move(exception))); + std::forward(exception))); } /// Raise an interrupt. If the promise holder has an interrupt diff --git a/folly/test/ApplyTupleTest.cpp b/folly/test/ApplyTupleTest.cpp index aad25c11..92ebac3f 100644 --- a/folly/test/ApplyTupleTest.cpp +++ b/folly/test/ApplyTupleTest.cpp @@ -84,8 +84,8 @@ typedef GuardObjBase const& Guard; template struct GuardObj : GuardObjBase { explicit GuardObj(F&& f, Tuple&& args) - : f_(std::move(f)) - , args_(std::move(args)) + : f_(std::forward(f)) + , args_(std::forward(args)) {} GuardObj(GuardObj&& g) noexcept : GuardObjBase(std::move(g)) diff --git a/folly/test/MPMCQueueTest.cpp b/folly/test/MPMCQueueTest.cpp index 7cd2452f..e3cd980c 100644 --- a/folly/test/MPMCQueueTest.cpp +++ b/folly/test/MPMCQueueTest.cpp @@ -104,7 +104,7 @@ TEST(MPMCQueue, sequencer_deterministic) { template void runElementTypeTest(T&& src) { MPMCQueue cq(10); - cq.blockingWrite(std::move(src)); + cq.blockingWrite(std::forward(src)); T dest; cq.blockingRead(dest); EXPECT_TRUE(cq.write(std::move(dest))); -- 2.34.1