Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1029)

Unified Diff: base/scoped_generic.h

Issue 995093002: Add additional move support to ScopedGeneric in the form of operator=. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nit Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/scoped_generic_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/scoped_generic.h
diff --git a/base/scoped_generic.h b/base/scoped_generic.h
index da42609e5c484cefc5024f9968f836ea0292eecc..f6807e2b58f2fa3fe425b5e9b0e51a4725b5d963 100644
--- a/base/scoped_generic.h
+++ b/base/scoped_generic.h
@@ -53,7 +53,7 @@ namespace base {
// typedef ScopedGeneric<int, FooScopedTraits> ScopedFoo;
template<typename T, typename Traits>
class ScopedGeneric {
- MOVE_ONLY_TYPE_FOR_CPP_03(ScopedGeneric, RValue)
+ MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedGeneric)
private:
// This must be first since it's used inline below.
@@ -83,15 +83,21 @@ class ScopedGeneric {
: data_(value, traits) {
}
- // Move constructor for C++03 move emulation.
- ScopedGeneric(RValue rvalue)
- : data_(rvalue.object->release(), rvalue.object->get_traits()) {
+ // Move constructor. Allows initialization from a ScopedGeneric rvalue.
+ ScopedGeneric(ScopedGeneric<T, Traits>&& rvalue)
+ : data_(rvalue.release(), rvalue.get_traits()) {
}
~ScopedGeneric() {
FreeIfNecessary();
}
+ // operator=. Allows assignment from a ScopedGeneric rvalue.
+ ScopedGeneric& operator=(ScopedGeneric<T, Traits>&& rvalue) {
+ reset(rvalue.release());
+ return *this;
+ }
+
// Frees the currently owned object, if any. Then takes ownership of a new
// object, if given. Self-resets are not allowd as on scoped_ptr. See
// http://crbug.com/162971
« no previous file with comments | « no previous file | base/scoped_generic_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698