OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 PlatformSTL_h | 5 #ifndef PlatformSTL_h |
6 #define PlatformSTL_h | 6 #define PlatformSTL_h |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #define PLATFORM_EXPORT | 10 #define PLATFORM_EXPORT |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 unique_ptr& operator=(std::nullptr_t) { reset(); return *this; } | 151 unique_ptr& operator=(std::nullptr_t) { reset(); return *this; } |
152 | 152 |
153 unique_ptr& operator=(const unique_ptr&); | 153 unique_ptr& operator=(const unique_ptr&); |
154 unique_ptr& operator=(unique_ptr&&); | 154 unique_ptr& operator=(unique_ptr&&); |
155 template <typename U> unique_ptr& operator=(unique_ptr<U>&&); | 155 template <typename U> unique_ptr& operator=(unique_ptr<U>&&); |
156 | 156 |
157 void swap(unique_ptr& o) { std::swap(m_ptr, o.m_ptr); } | 157 void swap(unique_ptr& o) { std::swap(m_ptr, o.m_ptr); } |
158 | 158 |
159 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } | 159 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } |
160 | 160 |
161 explicit unique_ptr(PtrType ptr) : m_ptr(ptr) {} | 161 explicit unique_ptr(PtrType ptr) : m_ptr(ptr) {} // NOLINT |
162 | 162 |
163 private: | 163 private: |
164 PtrType internalRelease() const | 164 PtrType internalRelease() const |
165 { | 165 { |
166 PtrType ptr = m_ptr; | 166 PtrType ptr = m_ptr; |
167 m_ptr = nullptr; | 167 m_ptr = nullptr; |
168 return ptr; | 168 return ptr; |
169 } | 169 } |
170 | 170 |
171 // We should never have two unique_ptrs for the same underlying object | 171 // We should never have two unique_ptrs for the same underlying object |
(...skipping 23 matching lines...) Expand all Loading... |
195 } | 195 } |
196 | 196 |
197 template <typename T> inline typename unique_ptr<T>::ValueType& unique_ptr<T>::o
perator[](std::ptrdiff_t i) const | 197 template <typename T> inline typename unique_ptr<T>::ValueType& unique_ptr<T>::o
perator[](std::ptrdiff_t i) const |
198 { | 198 { |
199 static_assert(is_array<T>::value, "elements access is possible for arrays on
ly"); | 199 static_assert(is_array<T>::value, "elements access is possible for arrays on
ly"); |
200 DCHECK(m_ptr); | 200 DCHECK(m_ptr); |
201 DCHECK_GE(i, 0); | 201 DCHECK_GE(i, 0); |
202 return m_ptr[i]; | 202 return m_ptr[i]; |
203 } | 203 } |
204 | 204 |
205 template <typename T> inline unique_ptr<T>::unique_ptr(const unique_ptr<T>& o) | 205 template <typename T> inline unique_ptr<T>::unique_ptr(const unique_ptr<T>& o)
// NOLINT |
206 : m_ptr(o.internalRelease()) | 206 : m_ptr(o.internalRelease()) |
207 { | 207 { |
208 } | 208 } |
209 | 209 |
210 template <typename T> inline unique_ptr<T>::unique_ptr(unique_ptr<T>&& o) | 210 template <typename T> inline unique_ptr<T>::unique_ptr(unique_ptr<T>&& o) // NO
LINT |
211 : m_ptr(o.internalRelease()) | 211 : m_ptr(o.internalRelease()) |
212 { | 212 { |
213 } | 213 } |
214 | 214 |
215 template <typename T> | 215 template <typename T> |
216 template <typename U, typename> inline unique_ptr<T>::unique_ptr(unique_ptr<U>&&
o) | 216 template <typename U, typename> inline unique_ptr<T>::unique_ptr(unique_ptr<U>&&
o) |
217 : m_ptr(o.release()) | 217 : m_ptr(o.release()) |
218 { | 218 { |
219 static_assert(!is_array<T>::value, "pointers to array must never be converte
d"); | 219 static_assert(!is_array<T>::value, "pointers to array must never be converte
d"); |
220 } | 220 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 283 |
284 #endif // defined(__APPLE__) && !defined(_LIBCPP_VERSION) | 284 #endif // defined(__APPLE__) && !defined(_LIBCPP_VERSION) |
285 | 285 |
286 template <typename T> | 286 template <typename T> |
287 std::unique_ptr<T> wrapUnique(T* ptr) | 287 std::unique_ptr<T> wrapUnique(T* ptr) |
288 { | 288 { |
289 return std::unique_ptr<T>(ptr); | 289 return std::unique_ptr<T>(ptr); |
290 } | 290 } |
291 | 291 |
292 #endif // PlatformSTL_h | 292 #endif // PlatformSTL_h |
OLD | NEW |