OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Scopers help you manage ownership of a pointer, helping you easily manage a | 5 // Scopers help you manage ownership of a pointer, helping you easily manage a |
6 // pointer within a scope, and automatically destroying the pointer at the end | 6 // pointer within a scope, and automatically destroying the pointer at the end |
7 // of a scope. There are two main classes you will use, which correspond to the | 7 // of a scope. There are two main classes you will use, which correspond to the |
8 // operators new/delete and new[]/delete[]. | 8 // operators new/delete and new[]/delete[]. |
9 // | 9 // |
10 // Example usage (scoped_ptr<T>): | 10 // Example usage (scoped_ptr<T>): |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // comments inside scoped_ptr_impl<> for details. | 232 // comments inside scoped_ptr_impl<> for details. |
233 // | 233 // |
234 // Current implementation targets having a strict subset of C++11's | 234 // Current implementation targets having a strict subset of C++11's |
235 // unique_ptr<> features. Known deficiencies include not supporting move-only | 235 // unique_ptr<> features. Known deficiencies include not supporting move-only |
236 // deleteres, function pointers as deleters, and deleters with reference | 236 // deleteres, function pointers as deleters, and deleters with reference |
237 // types. | 237 // types. |
238 template <class T, class D = std::default_delete<T>> | 238 template <class T, class D = std::default_delete<T>> |
239 class scoped_ptr { | 239 class scoped_ptr { |
240 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(scoped_ptr) | 240 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(scoped_ptr) |
241 | 241 |
242 COMPILE_ASSERT(base::internal::IsNotRefCounted<T>::value, | 242 static_assert(base::internal::IsNotRefCounted<T>::value, |
243 T_is_refcounted_type_and_needs_scoped_refptr); | 243 "T is a refcounted type and needs a scoped_refptr"); |
244 | 244 |
245 public: | 245 public: |
246 // The element and deleter types. | 246 // The element and deleter types. |
247 using element_type = T; | 247 using element_type = T; |
248 using deleter_type = D; | 248 using deleter_type = D; |
249 | 249 |
250 // Constructor. Defaults to initializing with nullptr. | 250 // Constructor. Defaults to initializing with nullptr. |
251 scoped_ptr() : impl_(nullptr) {} | 251 scoped_ptr() : impl_(nullptr) {} |
252 | 252 |
253 // Constructor. Takes ownership of p. | 253 // Constructor. Takes ownership of p. |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 scoped_ptr<T> make_scoped_ptr(T* ptr) { | 595 scoped_ptr<T> make_scoped_ptr(T* ptr) { |
596 return scoped_ptr<T>(ptr); | 596 return scoped_ptr<T>(ptr); |
597 } | 597 } |
598 | 598 |
599 template <typename T> | 599 template <typename T> |
600 std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) { | 600 std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) { |
601 return out << p.get(); | 601 return out << p.get(); |
602 } | 602 } |
603 | 603 |
604 #endif // BASE_MEMORY_SCOPED_PTR_H_ | 604 #endif // BASE_MEMORY_SCOPED_PTR_H_ |
OLD | NEW |