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

Unified Diff: base/memory/ptr_util.h

Issue 1513423002: Add WrapUnique helper to wrap a raw pointer in a std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « base/memory/BUILD.gn ('k') | base/memory/ptr_util_unittest.cc » ('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
new file mode 100644
index 0000000000000000000000000000000000000000..eba389fa5137bf78d3b89e8f88f5e400a41c516c
--- /dev/null
+++ b/base/memory/ptr_util.h
@@ -0,0 +1,23 @@
+// Copyright 2015 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.
+
+#ifndef BASE_MEMORY_PTR_UTIL_H_
+#define BASE_MEMORY_PTR_UTIL_H_
+
+#include <memory>
+#include <type_traits>
+
+namespace base {
+
+// Helper function to transfer ownership of a raw pointer to a std::unique_ptr.
+template <typename T>
+std::unique_ptr<T> WrapUnique(T* ptr) {
danakj 2015/12/11 22:01:32 I don't understand the point of WrapUnique(T*), th
dcheng 2015/12/11 22:54:26 I think in a world where every owned pointer was r
+ static_assert(!std::is_array<T>::value || std::extent<T>::value != 0,
dcheng 2015/12/11 21:32:01 After puzzling over this, I still don't understand
danakj 2015/12/12 00:01:22 OK history of this appears to be along the lines o
dcheng 2015/12/14 17:41:24 Done. I've also added some comments warning about
vmpstr 2015/12/14 19:05:39 I was nerdsniped by this and I kind of got a test
+ "cannot wrap a pointer to T[] or T[0]");
+ return std::unique_ptr<T>(ptr);
+}
+
+} // namespace base
+
+#endif // BASE_MEMORY_PTR_UTIL_H_
« no previous file with comments | « base/memory/BUILD.gn ('k') | base/memory/ptr_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698