Chromium Code Reviews| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 // comments inside scoped_ptr_impl<> for details. | 233 // comments inside scoped_ptr_impl<> for details. |
| 234 // | 234 // |
| 235 // Current implementation targets having a strict subset of C++11's | 235 // Current implementation targets having a strict subset of C++11's |
| 236 // unique_ptr<> features. Known deficiencies include not supporting move-only | 236 // unique_ptr<> features. Known deficiencies include not supporting move-only |
| 237 // deleteres, function pointers as deleters, and deleters with reference | 237 // deleteres, function pointers as deleters, and deleters with reference |
| 238 // types. | 238 // types. |
| 239 template <class T, class D = std::default_delete<T>> | 239 template <class T, class D = std::default_delete<T>> |
| 240 class scoped_ptr { | 240 class scoped_ptr { |
| 241 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(scoped_ptr) | 241 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(scoped_ptr) |
| 242 | 242 |
| 243 static_assert(!std::is_array<T>::value, | |
|
dcheng
2015/12/10 18:19:40
!!!
thanks
| |
| 244 "scoped_ptr doesn't support array with size"); | |
| 243 static_assert(base::internal::IsNotRefCounted<T>::value, | 245 static_assert(base::internal::IsNotRefCounted<T>::value, |
| 244 "T is a refcounted type and needs a scoped_refptr"); | 246 "T is a refcounted type and needs a scoped_refptr"); |
| 245 | 247 |
| 246 public: | 248 public: |
| 247 // The element and deleter types. | 249 // The element and deleter types. |
| 248 using element_type = T; | 250 using element_type = T; |
| 249 using deleter_type = D; | 251 using deleter_type = D; |
| 250 | 252 |
| 251 // Constructor. Defaults to initializing with nullptr. | 253 // Constructor. Defaults to initializing with nullptr. |
| 252 scoped_ptr() : impl_(nullptr) {} | 254 scoped_ptr() : impl_(nullptr) {} |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 scoped_ptr<T> make_scoped_ptr(T* ptr) { | 598 scoped_ptr<T> make_scoped_ptr(T* ptr) { |
| 597 return scoped_ptr<T>(ptr); | 599 return scoped_ptr<T>(ptr); |
| 598 } | 600 } |
| 599 | 601 |
| 600 template <typename T> | 602 template <typename T> |
| 601 std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) { | 603 std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) { |
| 602 return out << p.get(); | 604 return out << p.get(); |
| 603 } | 605 } |
| 604 | 606 |
| 605 #endif // BASE_MEMORY_SCOPED_PTR_H_ | 607 #endif // BASE_MEMORY_SCOPED_PTR_H_ |
| OLD | NEW |