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

Unified Diff: base/memory/scoped_ptr.h

Issue 8968032: Allow construction and assignment of one scoped_ptr from another if the types are convertible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix copyright Created 8 years, 11 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/memory/scoped_ptr_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | base/memory/scoped_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698