Chromium Code Reviews| Index: base/memory/ref_counted.h |
| diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h |
| index 219437ed8d82b8b35835a6c3297d5f719f14c277..f50e355a4847c15f30c712dcb6f42a1d56714ef3 100644 |
| --- a/base/memory/ref_counted.h |
| +++ b/base/memory/ref_counted.h |
| @@ -14,6 +14,7 @@ |
| #ifndef NDEBUG |
| #include "base/logging.h" |
| #endif |
| +#include "base/move.h" |
| #include "base/threading/thread_collision_warner.h" |
| #include "build/build_config.h" |
| @@ -264,6 +265,7 @@ class RefCountedData |
| // |
| template <class T> |
| class scoped_refptr { |
| + TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(scoped_refptr) |
| public: |
| typedef T element_type; |
| @@ -286,6 +288,11 @@ class scoped_refptr { |
| AddRef(ptr_); |
| } |
| + template <typename U> |
| + scoped_refptr(scoped_refptr<U>&& r) : ptr_(r.get()) { |
| + r.ptr_ = nullptr; |
| + } |
| + |
| ~scoped_refptr() { |
| if (ptr_) |
| Release(ptr_); |
| @@ -323,6 +330,15 @@ class scoped_refptr { |
| return *this = r.get(); |
| } |
| + template <typename U> |
| + scoped_refptr& operator=(scoped_refptr<U>&& r) { |
| + if (ptr_ && ptr_ != r.ptr_) |
| + Release(ptr_); |
| + ptr_ = r.ptr_; |
| + r.ptr_ = nullptr; |
|
dcheng
2015/04/09 23:50:07
I think this doesn't work for a self-move assignme
Kibeom Kim (inactive)
2015/04/10 02:42:07
Done.
|
| + return *this; |
| + } |
| + |
| void swap(T** pp) { |
| T* p = ptr_; |
| ptr_ = *pp; |
| @@ -334,6 +350,8 @@ class scoped_refptr { |
| } |
| private: |
| + template <typename U> friend class scoped_refptr; |
| + |
| // Allow scoped_refptr<T> to be used in boolean expressions, but not |
| // implicitly convertible to a real bool (which is dangerous). |
| // |