| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PtrUtil_h | 5 #ifndef PtrUtil_h |
| 6 #define PtrUtil_h | 6 #define PtrUtil_h |
| 7 | 7 |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "platform/wtf/TypeTraits.h" | 9 #include "platform/wtf/TypeTraits.h" |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <type_traits> |
| 12 | 13 |
| 13 namespace WTF { | 14 namespace WTF { |
| 14 | 15 |
| 15 template <typename T> | 16 template <typename T> |
| 16 std::unique_ptr<T> wrapUnique(T* ptr) { | 17 std::unique_ptr<T> wrapUnique(T* ptr) { |
| 17 static_assert( | 18 static_assert( |
| 18 !WTF::IsGarbageCollectedType<T>::value, | 19 !WTF::IsGarbageCollectedType<T>::value, |
| 19 "Garbage collected types should not be stored in std::unique_ptr!"); | 20 "Garbage collected types should not be stored in std::unique_ptr!"); |
| 20 return std::unique_ptr<T>(ptr); | 21 return std::unique_ptr<T>(ptr); |
| 21 } | 22 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 -> decltype(base::MakeUnique<T>(std::forward<Args>(args)...)) { | 35 -> decltype(base::MakeUnique<T>(std::forward<Args>(args)...)) { |
| 35 static_assert( | 36 static_assert( |
| 36 !WTF::IsGarbageCollectedType<T>::value, | 37 !WTF::IsGarbageCollectedType<T>::value, |
| 37 "Garbage collected types should not be stored in std::unique_ptr!"); | 38 "Garbage collected types should not be stored in std::unique_ptr!"); |
| 38 return base::MakeUnique<T>(std::forward<Args>(args)...); | 39 return base::MakeUnique<T>(std::forward<Args>(args)...); |
| 39 } | 40 } |
| 40 | 41 |
| 41 template <typename T> | 42 template <typename T> |
| 42 auto makeUnique(size_t size) -> decltype(base::MakeUnique<T>(size)) { | 43 auto makeUnique(size_t size) -> decltype(base::MakeUnique<T>(size)) { |
| 43 static_assert( | 44 static_assert( |
| 44 !WTF::IsGarbageCollectedType<T>::value, | 45 !WTF::IsGarbageCollectedType<std::remove_extent<T>>::value, |
| 45 "Garbage collected types should not be stored in std::unique_ptr!"); | 46 "Garbage collected types should not be stored in std::unique_ptr!"); |
| 46 return base::MakeUnique<T>(size); | 47 return base::MakeUnique<T>(size); |
| 47 } | 48 } |
| 48 | 49 |
| 49 } // namespace WTF | 50 } // namespace WTF |
| 50 | 51 |
| 51 using WTF::wrapArrayUnique; | 52 using WTF::wrapArrayUnique; |
| 52 | 53 |
| 53 #endif // PtrUtil_h | 54 #endif // PtrUtil_h |
| OLD | NEW |