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

Unified Diff: base/memory/scoped_ptr.h

Issue 1432193002: Add std::unique_ptr conversions to scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 10 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 282a014869b6f12231df0b4c753506c5f5494a06..fae6a9ba32c4cf38b58e268e9e93724dc6cac301 100644
--- a/base/memory/scoped_ptr.h
+++ b/base/memory/scoped_ptr.h
@@ -145,6 +145,12 @@ class scoped_ptr_impl {
}
template <typename U, typename V>
+ void TakeState(std::unique_ptr<U, V>* other) {
+ reset(other->release());
+ get_deleter() = other->get_deleter();
+ }
+
+ template <typename U, typename V>
void TakeState(scoped_ptr_impl<U, V>* other) {
// See comment in templated constructor above regarding lack of support
// for move-only deleters.
@@ -394,6 +400,22 @@ class scoped_ptr {
return impl_.release();
}
+ // Conversion shims to help with the std::unique_ptr transition.
+ template <typename U, typename V>
+ scoped_ptr(std::unique_ptr<U, V>&& p)
+ : impl_(p.release(), p.get_deleter()) {}
+
+ template <typename U, typename V>
+ scoped_ptr& operator=(std::unique_ptr<U, V>&& p) {
+ impl_.TakeState(&p);
+ return *this;
+ }
+
+ template <typename U, typename V>
+ operator std::unique_ptr<U, V>() && {
+ return std::unique_ptr<U, V>(release(), get_deleter());
+ }
+
private:
// Needed to reach into |impl_| in the constructor.
template <typename U, typename V> friend class scoped_ptr;
@@ -486,6 +508,19 @@ class scoped_ptr<T[], D> {
return impl_.release();
}
+ // Conversion shims to help with the std::unique_ptr transition.
+ scoped_ptr(std::unique_ptr<T[], D>&& p)
+ : impl_(p.release(), p.get_deleter()) {}
+
+ scoped_ptr& operator=(std::unique_ptr<T[], D>&& p) {
+ impl_.TakeState(&p);
+ return *this;
+ }
+
+ operator std::unique_ptr<T[], D>() && {
+ return std::unique_ptr<T[], D>(release(), get_deleter());
+ }
+
private:
// Force element_type to be a complete type.
enum { type_must_be_complete = sizeof(element_type) };
« 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