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