Index: base/memory/scoped_ptr.h |
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h |
index bf2e0b6f0680ce2beaa83a46f8bc6195e3fb9abe..f1c4b594e49656746c4e229624c501fedc2b38c0 100644 |
--- a/base/memory/scoped_ptr.h |
+++ b/base/memory/scoped_ptr.h |
@@ -189,7 +189,7 @@ template <typename T> struct IsNotRefCounted { |
template <class T, class D> |
class scoped_ptr_impl { |
public: |
- explicit scoped_ptr_impl(T* p) : data_(p) { } |
+ explicit scoped_ptr_impl(T* p) : data_(p) {} |
// Initializer for deleters that have data parameters. |
scoped_ptr_impl(T* p, const D& d) : data_(p, d) {} |
@@ -319,13 +319,16 @@ class scoped_ptr { |
typedef D deleter_type; |
// Constructor. Defaults to initializing with NULL. |
- scoped_ptr() : impl_(NULL) { } |
+ scoped_ptr() : impl_(NULL) {} |
jamesr
2014/09/25 05:58:08
nit: impl_(nullptr) ?
|
// Constructor. Takes ownership of p. |
- explicit scoped_ptr(element_type* p) : impl_(p) { } |
+ explicit scoped_ptr(element_type* p) : impl_(p) {} |
// Constructor. Allows initialization of a stateful deleter. |
- scoped_ptr(element_type* p, const D& d) : impl_(p, d) { } |
+ scoped_ptr(element_type* p, const D& d) : impl_(p, d) {} |
+ |
+ // Constructor. Allows construction from a nullptr. |
+ scoped_ptr(decltype(nullptr)) : impl_(NULL) {} |
// Constructor. Allows construction from a scoped_ptr rvalue for a |
// convertible type and deleter. |
@@ -338,12 +341,13 @@ class scoped_ptr { |
// use of SFINAE. You only need to care about this if you modify the |
// implementation of scoped_ptr. |
template <typename U, typename V> |
- scoped_ptr(scoped_ptr<U, V> other) : impl_(&other.impl_) { |
+ scoped_ptr(scoped_ptr<U, V>&& other) |
+ : impl_(&other.impl_) { |
COMPILE_ASSERT(!base::is_array<U>::value, U_cannot_be_an_array); |
} |
// Constructor. Move constructor for C++03 move emulation of this type. |
- scoped_ptr(RValue rvalue) : impl_(&rvalue.object->impl_) { } |
+ scoped_ptr(RValue rvalue) : impl_(&rvalue.object->impl_) {} |
// operator=. Allows assignment from a scoped_ptr rvalue for a convertible |
// type and deleter. |
@@ -356,12 +360,19 @@ class scoped_ptr { |
// You only need to care about this if you modify the implementation of |
// scoped_ptr. |
template <typename U, typename V> |
- scoped_ptr& operator=(scoped_ptr<U, V> rhs) { |
+ scoped_ptr& operator=(scoped_ptr<U, V>&& rhs) { |
COMPILE_ASSERT(!base::is_array<U>::value, U_cannot_be_an_array); |
impl_.TakeState(&rhs.impl_); |
return *this; |
} |
+ // operator=. Allows assignment from a nullptr. Deletes the currently owned |
+ // object, if any. |
+ scoped_ptr& operator=(decltype(nullptr)) { |
+ reset(); |
+ return *this; |
+ } |
+ |
// Reset. Deletes the currently owned object, if any. |
// Then takes ownership of a new object, if given. |
void reset(element_type* p = NULL) { impl_.reset(p); } |
@@ -453,7 +464,7 @@ class scoped_ptr<T[], D> { |
typedef D deleter_type; |
// Constructor. Defaults to initializing with NULL. |
- scoped_ptr() : impl_(NULL) { } |
+ scoped_ptr() : impl_(NULL) {} |
jamesr
2014/09/25 05:58:08
s/NULL/nullptr/, same for the rest of file
|
// Constructor. Stores the given array. Note that the argument's type |
// must exactly match T*. In particular: |
@@ -471,10 +482,22 @@ class scoped_ptr<T[], D> { |
// to work around this may use implicit_cast<const T*>(). |
// However, because of the first bullet in this comment, users MUST |
// NOT use implicit_cast<Base*>() to upcast the static type of the array. |
- explicit scoped_ptr(element_type* array) : impl_(array) { } |
+ explicit scoped_ptr(element_type* array) : impl_(array) {} |
+ |
+ // Constructor. Allows construction from a nullptr. |
+ scoped_ptr(decltype(nullptr)) : impl_(NULL) {} |
+ |
+ // Constructor. Allows construction from a scoped_ptr rvalue. |
+ scoped_ptr(scoped_ptr&& other) : impl_(&other.impl_) {} |
// Constructor. Move constructor for C++03 move emulation of this type. |
- scoped_ptr(RValue rvalue) : impl_(&rvalue.object->impl_) { } |
+ scoped_ptr(RValue rvalue) : impl_(&rvalue.object->impl_) {} |
+ |
+ // operator=. Allows assignment from a scoped_ptr rvalue. |
+ scoped_ptr& operator=(scoped_ptr&& rhs) { |
+ impl_.TakeState(&rhs.impl_); |
+ return *this; |
+ } |
// operator=. Move operator= for C++03 move emulation of this type. |
scoped_ptr& operator=(RValue rhs) { |
@@ -482,6 +505,13 @@ class scoped_ptr<T[], D> { |
return *this; |
} |
+ // operator=. Allows assignment from a nullptr. Deletes the currently owned |
+ // array, if any. |
+ scoped_ptr& operator=(decltype(nullptr)) { |
+ reset(); |
+ return *this; |
+ } |
+ |
// Reset. Deletes the currently owned array, if any. |
// Then takes ownership of a new object, if given. |
void reset(element_type* array = NULL) { impl_.reset(array); } |