Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_ | |
| OLD | NEW |