Commit d7842974 authored by Sven Over's avatar Sven Over Committed by Facebook Github Bot 2

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
parent 056ba743
...@@ -78,7 +78,7 @@ to(const Src & value) { ...@@ -78,7 +78,7 @@ to(const Src & value) {
template <class Tgt, class Src> template <class Tgt, class Src>
typename std::enable_if<std::is_same<Tgt, Src>::value, Tgt>::type typename std::enable_if<std::is_same<Tgt, Src>::value, Tgt>::type
to(Src && value) { to(Src && value) {
return std::move(value); return std::forward<Src>(value);
} }
/******************************************************************************* /*******************************************************************************
......
...@@ -662,7 +662,7 @@ class Subprocess { ...@@ -662,7 +662,7 @@ class Subprocess {
uint64_t maxLineLength = 0, // No line length limit by default uint64_t maxLineLength = 0, // No line length limit by default
char delimiter = '\n', char delimiter = '\n',
uint64_t bufSize = 1024 uint64_t bufSize = 1024
) : fdLineCb_(std::move(fdLineCb)), ) : fdLineCb_(std::forward<Callback>(fdLineCb)),
maxLineLength_(maxLineLength), maxLineLength_(maxLineLength),
delimiter_(delimiter), delimiter_(delimiter),
bufSize_(bufSize) {} bufSize_(bufSize) {}
......
...@@ -331,7 +331,7 @@ class Future { ...@@ -331,7 +331,7 @@ class Future {
template <class E> template <class E>
void raise(E&& exception) { void raise(E&& exception) {
raise(make_exception_wrapper<typename std::remove_reference<E>::type>( raise(make_exception_wrapper<typename std::remove_reference<E>::type>(
std::move(exception))); std::forward<E>(exception)));
} }
/// Raise an interrupt. If the promise holder has an interrupt /// Raise an interrupt. If the promise holder has an interrupt
......
...@@ -84,8 +84,8 @@ typedef GuardObjBase const& Guard; ...@@ -84,8 +84,8 @@ typedef GuardObjBase const& Guard;
template<class F, class Tuple> template<class F, class Tuple>
struct GuardObj : GuardObjBase { struct GuardObj : GuardObjBase {
explicit GuardObj(F&& f, Tuple&& args) explicit GuardObj(F&& f, Tuple&& args)
: f_(std::move(f)) : f_(std::forward<F>(f))
, args_(std::move(args)) , args_(std::forward<Tuple>(args))
{} {}
GuardObj(GuardObj&& g) noexcept GuardObj(GuardObj&& g) noexcept
: GuardObjBase(std::move(g)) : GuardObjBase(std::move(g))
......
...@@ -104,7 +104,7 @@ TEST(MPMCQueue, sequencer_deterministic) { ...@@ -104,7 +104,7 @@ TEST(MPMCQueue, sequencer_deterministic) {
template <typename T> template <typename T>
void runElementTypeTest(T&& src) { void runElementTypeTest(T&& src) {
MPMCQueue<T> cq(10); MPMCQueue<T> cq(10);
cq.blockingWrite(std::move(src)); cq.blockingWrite(std::forward<T>(src));
T dest; T dest;
cq.blockingRead(dest); cq.blockingRead(dest);
EXPECT_TRUE(cq.write(std::move(dest))); EXPECT_TRUE(cq.write(std::move(dest)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment