Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: base/memory/scoped_ptr.h

Issue 1810893003: Trim some headers from base/memory/scoped_ptr.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/base/contiguous_container.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // TODO(dcheng): Clean up these headers, but there are likely lots of existing 93 // TODO(dcheng): Clean up these headers, but there are likely lots of existing
94 // IWYU violations. 94 // IWYU violations.
95 #include <stddef.h> 95 #include <stddef.h>
96 #include <stdlib.h> 96 #include <stdlib.h>
97 97
98 #include <iosfwd> 98 #include <iosfwd>
99 #include <memory> 99 #include <memory>
100 #include <type_traits> 100 #include <type_traits>
101 #include <utility> 101 #include <utility>
102 102
103 #include "base/compiler_specific.h"
104 #include "base/logging.h" 103 #include "base/logging.h"
105 #include "base/macros.h" 104 #include "base/macros.h"
106 #include "base/move.h"
107 #include "build/build_config.h"
108 105
109 namespace base { 106 namespace base {
110 107
111 // Function object which invokes 'free' on its parameter, which must be 108 // Function object which invokes 'free' on its parameter, which must be
112 // a pointer. Can be used to store malloc-allocated pointers in scoped_ptr: 109 // a pointer. Can be used to store malloc-allocated pointers in scoped_ptr:
113 // 110 //
114 // scoped_ptr<int, base::FreeDeleter> foo_ptr( 111 // scoped_ptr<int, base::FreeDeleter> foo_ptr(
115 // static_cast<int*>(malloc(sizeof(int)))); 112 // static_cast<int*>(malloc(sizeof(int))));
116 struct FreeDeleter { 113 struct FreeDeleter {
117 inline void operator()(void* ptr) const { 114 inline void operator()(void* ptr) const {
118 free(ptr); 115 free(ptr);
119 } 116 }
120 }; 117 };
121 118
122 } // namespace base 119 } // namespace base
123 120
124 template <typename T, typename D = std::default_delete<T>> 121 template <typename T, typename D = std::default_delete<T>>
125 using scoped_ptr = std::unique_ptr<T, D>; 122 using scoped_ptr = std::unique_ptr<T, D>;
126 123
127 // A function to convert T* into scoped_ptr<T> 124 // A function to convert T* into scoped_ptr<T>
128 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation 125 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation
129 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) 126 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
130 template <typename T> 127 template <typename T>
131 scoped_ptr<T> make_scoped_ptr(T* ptr) { 128 scoped_ptr<T> make_scoped_ptr(T* ptr) {
132 return scoped_ptr<T>(ptr); 129 return scoped_ptr<T>(ptr);
133 } 130 }
134 131
135 #endif // BASE_MEMORY_SCOPED_PTR_H_ 132 #endif // BASE_MEMORY_SCOPED_PTR_H_
OLDNEW
« no previous file with comments | « no previous file | cc/base/contiguous_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698