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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 #define BASE_MEMORY_SCOPED_PTR_H_ | 78 #define BASE_MEMORY_SCOPED_PTR_H_ |
79 | 79 |
80 // This is an implementation designed to match the anticipated future TR2 | 80 // This is an implementation designed to match the anticipated future TR2 |
81 // implementation of the scoped_ptr class. | 81 // implementation of the scoped_ptr class. |
82 | 82 |
83 #include <assert.h> | 83 #include <assert.h> |
84 #include <stddef.h> | 84 #include <stddef.h> |
85 #include <stdlib.h> | 85 #include <stdlib.h> |
86 | 86 |
87 #include <algorithm> // For std::swap(). | 87 #include <algorithm> // For std::swap(). |
| 88 #include <iosfwd> |
88 | 89 |
89 #include "base/basictypes.h" | 90 #include "base/basictypes.h" |
90 #include "base/compiler_specific.h" | 91 #include "base/compiler_specific.h" |
91 #include "base/move.h" | 92 #include "base/move.h" |
92 #include "base/template_util.h" | 93 #include "base/template_util.h" |
93 | 94 |
94 namespace base { | 95 namespace base { |
95 | 96 |
96 namespace subtle { | 97 namespace subtle { |
97 class RefCountedBase; | 98 class RefCountedBase; |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 } | 579 } |
579 | 580 |
580 // A function to convert T* into scoped_ptr<T> | 581 // A function to convert T* into scoped_ptr<T> |
581 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 582 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
582 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 583 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
583 template <typename T> | 584 template <typename T> |
584 scoped_ptr<T> make_scoped_ptr(T* ptr) { | 585 scoped_ptr<T> make_scoped_ptr(T* ptr) { |
585 return scoped_ptr<T>(ptr); | 586 return scoped_ptr<T>(ptr); |
586 } | 587 } |
587 | 588 |
| 589 template <typename T> |
| 590 std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) { |
| 591 return out << p.get(); |
| 592 } |
| 593 |
588 #endif // BASE_MEMORY_SCOPED_PTR_H_ | 594 #endif // BASE_MEMORY_SCOPED_PTR_H_ |
OLD | NEW |