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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 inline void operator()(void* ptr) const { | 116 inline void operator()(void* ptr) const { |
117 free(ptr); | 117 free(ptr); |
118 } | 118 } |
119 }; | 119 }; |
120 | 120 |
121 } // namespace base | 121 } // namespace base |
122 | 122 |
123 // Now that scoped_ptr is almost 100% compatible with std::unique_ptr, we're | 123 // Now that scoped_ptr is almost 100% compatible with std::unique_ptr, we're |
124 // incrementally migrating scoped_ptr to just be a type alias for | 124 // incrementally migrating scoped_ptr to just be a type alias for |
125 // std::unique_ptr. The eventual goal is to delete scoped_ptr altogether. | 125 // std::unique_ptr. The eventual goal is to delete scoped_ptr altogether. |
126 #if defined(OS_LINUX) || defined(OS_WIN) | 126 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_ANDROID) |
127 template <typename T, typename D = std::default_delete<T>> | 127 template <typename T, typename D = std::default_delete<T>> |
128 using scoped_ptr = std::unique_ptr<T, D>; | 128 using scoped_ptr = std::unique_ptr<T, D>; |
129 | 129 |
130 // Versions of libstdc++ 4.8 lack overloads for <, <=, >, and >= when comparing | 130 // Versions of libstdc++ 4.8 lack overloads for <, <=, >, and >= when comparing |
131 // a std::unique_ptr and nullptr_t. | 131 // a std::unique_ptr and nullptr_t. |
132 #if defined(__GLIBCXX__) && __GLIBCXX__ < 20150123 | 132 #if defined(__GLIBCXX__) && __GLIBCXX__ < 20150123 |
133 template <class T, class D> | 133 template <class T, class D> |
134 bool operator<(const scoped_ptr<T, D>& p, std::nullptr_t) { | 134 bool operator<(const scoped_ptr<T, D>& p, std::nullptr_t) { |
135 return p.get() < nullptr; | 135 return p.get() < nullptr; |
136 } | 136 } |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 671 |
672 // A function to convert T* into scoped_ptr<T> | 672 // A function to convert T* into scoped_ptr<T> |
673 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 673 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
674 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 674 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
675 template <typename T> | 675 template <typename T> |
676 scoped_ptr<T> make_scoped_ptr(T* ptr) { | 676 scoped_ptr<T> make_scoped_ptr(T* ptr) { |
677 return scoped_ptr<T>(ptr); | 677 return scoped_ptr<T>(ptr); |
678 } | 678 } |
679 | 679 |
680 #endif // BASE_MEMORY_SCOPED_PTR_H_ | 680 #endif // BASE_MEMORY_SCOPED_PTR_H_ |
OLD | NEW |