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 |
danakj
2016/03/28 21:42:55
Can you delete all the comments and just "// scope
dcheng
2016/03/28 21:44:41
Done.
| |
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>): |
11 // { | 11 // { |
12 // scoped_ptr<Foo> foo(new Foo("wee")); | 12 // scoped_ptr<Foo> foo(new Foo("wee")); |
13 // } // foo goes out of scope, releasing the pointer with it. | 13 // } // foo goes out of scope, releasing the pointer with it. |
14 // | 14 // |
15 // { | 15 // { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 // | 83 // |
84 // scoped_ptr<Foo> foo(new Foo()); | 84 // scoped_ptr<Foo> foo(new Foo()); |
85 // scoped_ptr<FooParent> parent(std::move(foo)); | 85 // scoped_ptr<FooParent> parent(std::move(foo)); |
86 | 86 |
87 #ifndef BASE_MEMORY_SCOPED_PTR_H_ | 87 #ifndef BASE_MEMORY_SCOPED_PTR_H_ |
88 #define BASE_MEMORY_SCOPED_PTR_H_ | 88 #define BASE_MEMORY_SCOPED_PTR_H_ |
89 | 89 |
90 // This is an implementation designed to match the anticipated future TR2 | 90 // This is an implementation designed to match the anticipated future TR2 |
91 // implementation of the scoped_ptr class. | 91 // implementation of the scoped_ptr class. |
92 | 92 |
93 // TODO(dcheng): Clean up these headers, but there are likely lots of existing | |
94 // IWYU violations. | |
95 #include <stdlib.h> | |
96 | |
97 #include <memory> | 93 #include <memory> |
98 | 94 |
99 template <typename T, typename D = std::default_delete<T>> | 95 template <typename T, typename D = std::default_delete<T>> |
100 using scoped_ptr = std::unique_ptr<T, D>; | 96 using scoped_ptr = std::unique_ptr<T, D>; |
101 | 97 |
102 // A function to convert T* into scoped_ptr<T> | 98 // A function to convert T* into scoped_ptr<T> |
103 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 99 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
104 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 100 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
105 template <typename T> | 101 template <typename T> |
106 scoped_ptr<T> make_scoped_ptr(T* ptr) { | 102 scoped_ptr<T> make_scoped_ptr(T* ptr) { |
107 return scoped_ptr<T>(ptr); | 103 return scoped_ptr<T>(ptr); |
108 } | 104 } |
109 | 105 |
110 #endif // BASE_MEMORY_SCOPED_PTR_H_ | 106 #endif // BASE_MEMORY_SCOPED_PTR_H_ |
OLD | NEW |