Lines Matching full:scoped_ptr
10 // Example usage (scoped_ptr<T>):
12 // scoped_ptr<Foo> foo(new Foo("wee"));
16 // scoped_ptr<Foo> foo; // No pointer managed.
29 // Example usage (scoped_ptr<T[]>):
31 // scoped_ptr<Foo[]> foo(new Foo[100]);
43 // using scoped_ptr:
45 // void TakesOwnership(scoped_ptr<Foo> arg) {
48 // scoped_ptr<Foo> CreateFoo() {
51 // return scoped_ptr<Foo>(new Foo("new"));
53 // scoped_ptr<Foo> PassThru(scoped_ptr<Foo> arg) {
58 // scoped_ptr<Foo> ptr(new Foo("yay")); // ptr manages Foo("yay").
60 // scoped_ptr<Foo> ptr2 = CreateFoo(); // ptr2 owns the return Foo.
61 // scoped_ptr<Foo> ptr3 = // ptr3 now owns what was in ptr2.
73 // i.e. you can use a scoped_ptr<Child> to initialize a scoped_ptr<Parent>:
75 // scoped_ptr<Foo> foo(new Foo());
76 // scoped_ptr<FooParent> parent(std::move(foo));
82 // implementation of the scoped_ptr class.
106 // a pointer. Can be used to store malloc-allocated pointers in scoped_ptr:
108 // scoped_ptr<int, base::FreeDeleter> foo_ptr(
126 // Minimal implementation of the core logic of scoped_ptr, suitable for
127 // reuse in both scoped_ptr and its specializations.
223 // A scoped_ptr<T> is like a T*, except that the destructor of scoped_ptr<T>
225 // That is, scoped_ptr<T> owns the T object that it points to.
226 // Like a T*, a scoped_ptr<T> may hold either nullptr or a pointer to a T
227 // object. Also like T*, scoped_ptr<T> is thread-compatible, and once you
230 // The size of scoped_ptr is small. On most compilers, when using the
231 // std::default_delete, sizeof(scoped_ptr<T>) == sizeof(T*). Custom deleters
240 class scoped_ptr {
241 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(scoped_ptr)
244 "scoped_ptr doesn't support array with size");
254 scoped_ptr() : impl_(nullptr) {}
257 explicit scoped_ptr(element_type* p) : impl_(p) {}
260 scoped_ptr(element_type* p, const D& d) : impl_(p, d) {}
263 scoped_ptr(std::nullptr_t) : impl_(nullptr) {}
273 scoped_ptr(scoped_ptr&& other) : impl_(&other.impl_) {}
275 // Conversion constructor. Allows construction from a scoped_ptr rvalue for a
282 // std::is_convertible<scoped_ptr<Base>, scoped_ptr<Derived>>::value
285 // void F(scoped_ptr<int>);
286 // void F(scoped_ptr<Base>);
288 // F(scoped_ptr<Derived>());
289 // - U is not an array type: to prevent conversions from scoped_ptr<T[]> to
290 // scoped_ptr<T>.
300 scoped_ptr(scoped_ptr<U, E>&& other)
312 scoped_ptr& operator=(scoped_ptr&& rhs) {
317 // operator=. Allows assignment from a scoped_ptr rvalue for a convertible
336 scoped_ptr& operator=(scoped_ptr<U, E>&& rhs) {
343 scoped_ptr& operator=(std::nullptr_t) {
368 // Allow scoped_ptr<element_type> to be used in boolean expressions, but not
377 scoped_ptr::*Testable;
381 return impl_.get() ? &scoped_ptr::impl_ : nullptr;
385 void swap(scoped_ptr& p2) {
399 template <typename U, typename V> friend class scoped_ptr;
403 explicit scoped_ptr(int disallow_construction_from_null);
407 class scoped_ptr<T[], D> {
408 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(scoped_ptr)
416 scoped_ptr() : impl_(nullptr) {}
429 explicit scoped_ptr(element_type* array) : impl_(array) {}
432 scoped_ptr(std::nullptr_t) : impl_(nullptr) {}
434 // Constructor. Allows construction from a scoped_ptr rvalue.
435 scoped_ptr(scoped_ptr&& other) : impl_(&other.impl_) {}
437 // operator=. Allows assignment from a scoped_ptr rvalue.
438 scoped_ptr& operator=(scoped_ptr&& rhs) {
445 scoped_ptr& operator=(std::nullptr_t) {
465 // Allow scoped_ptr<element_type> to be used in boolean expressions, but not
469 scoped_ptr::*Testable;
473 return impl_.get() ? &scoped_ptr::impl_ : nullptr;
477 void swap(scoped_ptr& p2) {
501 template <typename U> explicit scoped_ptr(U* array);
502 explicit scoped_ptr(int disallow_construction_from_null);
512 void swap(scoped_ptr<T, D>& p1, scoped_ptr<T, D>& p2) {
517 bool operator==(const scoped_ptr<T1, D1>& p1, const scoped_ptr<T2, D2>& p2) {
521 bool operator==(const scoped_ptr<T, D>& p, std::nullptr_t) {
525 bool operator==(std::nullptr_t, const scoped_ptr<T, D>& p) {
530 bool operator!=(const scoped_ptr<T1, D1>& p1, const scoped_ptr<T2, D2>& p2) {
534 bool operator!=(const scoped_ptr<T, D>& p, std::nullptr_t) {
538 bool operator!=(std::nullptr_t, const scoped_ptr<T, D>& p) {
543 bool operator<(const scoped_ptr<T1, D1>& p1, const scoped_ptr<T2, D2>& p2) {
547 bool operator<(const scoped_ptr<T, D>& p, std::nullptr_t) {
552 bool operator<(std::nullptr_t, const scoped_ptr<T, D>& p) {
558 bool operator>(const scoped_ptr<T1, D1>& p1, const scoped_ptr<T2, D2>& p2) {
562 bool operator>(const scoped_ptr<T, D>& p, std::nullptr_t) {
566 bool operator>(std::nullptr_t, const scoped_ptr<T, D>& p) {
571 bool operator<=(const scoped_ptr<T1, D1>& p1, const scoped_ptr<T2, D2>& p2) {
575 bool operator<=(const scoped_ptr<T, D>& p, std::nullptr_t) {
579 bool operator<=(std::nullptr_t, const scoped_ptr<T, D>& p) {
584 bool operator>=(const scoped_ptr<T1, D1>& p1, const scoped_ptr<T2, D2>& p2) {
588 bool operator>=(const scoped_ptr<T, D>& p, std::nullptr_t) {
592 bool operator>=(std::nullptr_t, const scoped_ptr<T, D>& p) {
596 // A function to convert T* into scoped_ptr<T>
598 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
600 scoped_ptr<T> make_scoped_ptr(T* ptr) {
601 return scoped_ptr<T>(ptr);
605 std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) {