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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/memory/BUILD.gn ('k') | base/memory/ptr_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_MEMORY_PTR_UTIL_H_
6 #define BASE_MEMORY_PTR_UTIL_H_
7
8 #include <memory>
9 #include <type_traits>
10
11 namespace base {
12
13 // Helper function to transfer ownership of a raw pointer to a std::unique_ptr.
14 template <typename T>
15 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
16 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
17 "cannot wrap a pointer to T[] or T[0]");
18 return std::unique_ptr<T>(ptr);
19 }
20
21 } // namespace base
22
23 #endif // BASE_MEMORY_PTR_UTIL_H_
OLDNEW
« 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