Replace manual casting to rvalue reference with calls to std::move
Review URL: https://codereview.webrtc.org/1570473002
Cr-Commit-Position: refs/heads/master@{#11163}
diff --git a/webrtc/base/buffer.h b/webrtc/base/buffer.h
index 076fa08..bf2e9f3 100644
--- a/webrtc/base/buffer.h
+++ b/webrtc/base/buffer.h
@@ -172,7 +172,7 @@
// b.Pass() does the same thing as std::move(b).
Buffer&& Pass() {
assert(IsConsistent());
- return static_cast<Buffer&&>(*this);
+ return std::move(*this);
}
// Resets the buffer to zero size and capacity. Works even if the buffer has
diff --git a/webrtc/base/optional.h b/webrtc/base/optional.h
index 6e7535b..b8071e63 100644
--- a/webrtc/base/optional.h
+++ b/webrtc/base/optional.h
@@ -66,20 +66,19 @@
// Construct an Optional that contains a value.
explicit Optional(const T& val) : value_(val), has_value_(true) {}
- explicit Optional(T&& val)
- : value_(static_cast<T&&>(val)), has_value_(true) {}
+ explicit Optional(T&& val) : value_(std::move(val)), has_value_(true) {}
// Copy and move constructors.
// TODO(kwiberg): =default the move constructor when MSVC supports it.
Optional(const Optional&) = default;
Optional(Optional&& m)
- : value_(static_cast<T&&>(m.value_)), has_value_(m.has_value_) {}
+ : value_(std::move(m.value_)), has_value_(m.has_value_) {}
// Assignment.
// TODO(kwiberg): =default the move assignment op when MSVC supports it.
Optional& operator=(const Optional&) = default;
Optional& operator=(Optional&& m) {
- value_ = static_cast<T&&>(m.value_);
+ value_ = std::move(m.value_);
has_value_ = m.has_value_;
return *this;
}
diff --git a/webrtc/base/optional_unittest.cc b/webrtc/base/optional_unittest.cc
index 5483314..eabf091 100644
--- a/webrtc/base/optional_unittest.cc
+++ b/webrtc/base/optional_unittest.cc
@@ -162,7 +162,7 @@
{
Optional<Logger> x;
EXPECT_FALSE(x);
- auto y = static_cast<Optional<Logger>&&>(x);
+ auto y = std::move(x);
EXPECT_FALSE(y);
}
EXPECT_EQ(V("0:0. default constructor", "1:0. move constructor (from 0:0)",
@@ -176,7 +176,7 @@
Optional<Logger> x(Logger(17));
EXPECT_TRUE(x);
log->push_back("---");
- auto y = static_cast<Optional<Logger>&&>(x);
+ auto y = std::move(x);
EXPECT_TRUE(x);
EXPECT_TRUE(y);
log->push_back("---");
@@ -289,7 +289,7 @@
auto log = Logger::Setup();
{
Optional<Logger> x, y;
- x = static_cast<Optional<Logger>&&>(y);
+ x = std::move(y);
}
EXPECT_EQ(
V("0:0. default constructor", "1:1. default constructor",
@@ -303,7 +303,7 @@
Optional<Logger> x(Logger(17));
Optional<Logger> y;
log->push_back("---");
- x = static_cast<Optional<Logger>&&>(y);
+ x = std::move(y);
log->push_back("---");
}
EXPECT_EQ(
@@ -320,7 +320,7 @@
Optional<Logger> x;
Optional<Logger> y(Logger(17));
log->push_back("---");
- x = static_cast<Optional<Logger>&&>(y);
+ x = std::move(y);
log->push_back("---");
}
EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor",
@@ -336,7 +336,7 @@
Optional<Logger> x(Logger(17));
Optional<Logger> y(Logger(42));
log->push_back("---");
- x = static_cast<Optional<Logger>&&>(y);
+ x = std::move(y);
log->push_back("---");
}
EXPECT_EQ(
@@ -354,7 +354,7 @@
Optional<Logger> x;
Logger y(17);
log->push_back("---");
- x = Optional<Logger>(static_cast<Logger&&>(y));
+ x = Optional<Logger>(std::move(y));
log->push_back("---");
}
EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor", "---",
@@ -370,7 +370,7 @@
Optional<Logger> x(Logger(17));
Logger y(42);
log->push_back("---");
- x = Optional<Logger>(static_cast<Logger&&>(y));
+ x = Optional<Logger>(std::move(y));
log->push_back("---");
}
EXPECT_EQ(
@@ -390,13 +390,13 @@
log->push_back("---");
x->Foo();
y->Foo();
- static_cast<Optional<Logger>&&>(x)->Foo();
- static_cast<const Optional<Logger>&&>(y)->Foo();
+ std::move(x)->Foo();
+ std::move(y)->Foo();
log->push_back("---");
(*x).Foo();
(*y).Foo();
- (*static_cast<Optional<Logger>&&>(x)).Foo();
- (*static_cast<const Optional<Logger>&&>(y)).Foo();
+ (*std::move(x)).Foo();
+ (*std::move(y)).Foo();
log->push_back("---");
}
EXPECT_EQ(V("0:42. explicit constructor",
diff --git a/webrtc/base/scoped_ptr.h b/webrtc/base/scoped_ptr.h
index db615f3..3f1a87a 100644
--- a/webrtc/base/scoped_ptr.h
+++ b/webrtc/base/scoped_ptr.h
@@ -374,7 +374,7 @@
scoped_ptr& operator=(const scoped_ptr& other) = delete;
// Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).)
- scoped_ptr&& Pass() { return static_cast<scoped_ptr&&>(*this); }
+ scoped_ptr&& Pass() { return std::move(*this); }
// Reset. Deletes the currently owned object, if any.
// Then takes ownership of a new object, if given.
@@ -507,7 +507,7 @@
scoped_ptr& operator=(const scoped_ptr& other) = delete;
// Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).)
- scoped_ptr&& Pass() { return static_cast<scoped_ptr&&>(*this); }
+ scoped_ptr&& Pass() { return std::move(*this); }
// Reset. Deletes the currently owned array, if any.
// Then takes ownership of a new object, if given.
diff --git a/webrtc/system_wrappers/include/scoped_vector.h b/webrtc/system_wrappers/include/scoped_vector.h
index 7336d98..284f437 100644
--- a/webrtc/system_wrappers/include/scoped_vector.h
+++ b/webrtc/system_wrappers/include/scoped_vector.h
@@ -43,9 +43,7 @@
~ScopedVector() { clear(); }
// Move construction and assignment.
- ScopedVector(ScopedVector&& other) {
- *this = static_cast<ScopedVector&&>(other);
- }
+ ScopedVector(ScopedVector&& other) { *this = std::move(other); }
ScopedVector& operator=(ScopedVector&& other) {
std::swap(v_, other.v_); // The arguments are std::vectors, so std::swap
// is the one that we want.
@@ -58,7 +56,7 @@
ScopedVector& operator=(const ScopedVector& other) = delete;
// Get an rvalue reference. (sv.Pass() does the same thing as std::move(sv).)
- ScopedVector&& Pass() { return static_cast<ScopedVector&&>(*this); }
+ ScopedVector&& Pass() { return std::move(*this); }
reference operator[](size_t index) { return v_[index]; }
const_reference operator[](size_t index) const { return v_[index]; }