Index: base/memory/scoped_ptr.h |
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h |
index 2d69a9db4489eb840ad65ad40087f08ecac7ff0d..b0cf0a1cae2e1e85b6c5f9d7dc2f9cd8f5047705 100644 |
--- a/base/memory/scoped_ptr.h |
+++ b/base/memory/scoped_ptr.h |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -126,6 +126,12 @@ class scoped_ptr { |
// The input parameter must be allocated with new. |
explicit scoped_ptr(C* p = NULL) : ptr_(p) { } |
+ // Constructor. Allows construction from a scoped_ptr rvalue for a |
+ // convertible type. |
+ template <typename U> |
+ scoped_ptr(scoped_ptr<U> other) : ptr_(other.release()) { |
+ } |
+ |
// Destructor. If there is a C object, delete it. |
// We don't need to test ptr_ == NULL because C++ does that for us. |
~scoped_ptr() { |
@@ -133,6 +139,14 @@ class scoped_ptr { |
delete ptr_; |
} |
+ // operator=. Allows assignment from a scoped_ptr rvalue for a convertible |
+ // type. |
+ template <typename U> |
+ scoped_ptr& operator=(scoped_ptr<U> rhs) { |
+ reset(rhs.release()); |
+ return *this; |
+ } |
+ |
// Reset. Deletes the current owned object, if any. |
// Then takes ownership of a new object, if given. |
// this->reset(this->get()) works. |