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

Unified Diff: base/memory/ptr_util.h

Issue 1838323002: Move make_scoped_ptr into //base/memory/ptr_util.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment fix Created 4 years, 9 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.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/ptr_util.h
diff --git a/base/memory/ptr_util.h b/base/memory/ptr_util.h
index 04f2c0258929e74c0bcca89d4433fa6f647a0d28..2c8db5e11893b7f41ee429ffade92ef0bde8fa02 100644
--- a/base/memory/ptr_util.h
+++ b/base/memory/ptr_util.h
@@ -7,6 +7,31 @@
#include <memory>
+// A function to convert T* into scoped_ptr<T>
+// Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation
+// for scoped_ptr<FooBarBaz<type>>(new FooBarBaz<type>(arg))
+//
+// Why doesn't this just return a scoped_ptr?
+//
+// make_scoped_ptr is currently being migrated out of scoped_ptr.h, so we can
+// globally rename make_scoped_ptr to WrapUnique without breaking the build.
+// Doing so without breaking intermediate builds involves several steps:
+//
+// 1. Move make_scoped_ptr into ptr_util.h and include ptr_util.h from
+// scoped_ptr.h.
+// 2. Add an #include for ptr_util.h to every file that references
+// make_scoped_ptr.
+// 3. Remove ptr_util.h include from scoped_ptr.h.
+// 4. Global rewrite everything.
+//
+// Unfortunately, step 1 introduces an awkward cycle of dependencies between
+// ptr_util.h and scoped_ptr.h To break that cycle, we exploit the fact that
+// scoped_ptr is really just a type alias for std::unique_ptr.
+template <typename T>
+std::unique_ptr<T> make_scoped_ptr(T* ptr) {
+ return std::unique_ptr<T>(ptr);
+}
+
namespace base {
// Helper to transfer ownership of a raw pointer to a std::unique_ptr<T>.
« no previous file with comments | « no previous file | base/memory/scoped_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698