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

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

Issue 13673002: Make scoped_array<T> more compatible with scoped_ptr<T[]>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Being ambitious. Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 the 5 // Scopers help you manage ownership of a pointer, helping you easily manage the
6 // a pointer within a scope, and automatically destroying the pointer at the 6 // a pointer within a scope, and automatically destroying the pointer at the
7 // end of a scope. There are two main classes you will use, which correspond 7 // end of a scope. There are two main classes you will use, which correspond
8 // to the operators new/delete and new[]/delete[]. 8 // to the operators new/delete and new[]/delete[].
9 // 9 //
10 // Example usage (scoped_ptr): 10 // Example usage (scoped_ptr):
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 // and will not own the object any more. 656 // and will not own the object any more.
657 C* release() WARN_UNUSED_RESULT { 657 C* release() WARN_UNUSED_RESULT {
658 C* retVal = array_; 658 C* retVal = array_;
659 array_ = NULL; 659 array_ = NULL;
660 return retVal; 660 return retVal;
661 } 661 }
662 662
663 private: 663 private:
664 C* array_; 664 C* array_;
665 665
666 // Disable initialization from any type other than C*, by providing a
667 // constructor that matches such an initialization, but is private and has no
668 // definition. This is disabled because it is not safe to call delete[] on an
669 // array whose static type does not match its dynamic type.
670 template <typename C2> explicit scoped_array(C2* array);
671 explicit scoped_array(int disallow_construction_from_null);
672
673 // Disable reset() from any type other than C*, for the same reasons as the
674 // constructor above.
675 template <typename C2> void reset(C2* array);
676 void reset(int disallow_reset_from_null);
677
666 // Forbid comparison of different scoped_array types. 678 // Forbid comparison of different scoped_array types.
667 template <class C2> bool operator==(scoped_array<C2> const& p2) const; 679 template <class C2> bool operator==(scoped_array<C2> const& p2) const;
668 template <class C2> bool operator!=(scoped_array<C2> const& p2) const; 680 template <class C2> bool operator!=(scoped_array<C2> const& p2) const;
669 }; 681 };
670 682
671 // Free functions 683 // Free functions
672 template <class C> 684 template <class C>
673 void swap(scoped_array<C>& p1, scoped_array<C>& p2) { 685 void swap(scoped_array<C>& p1, scoped_array<C>& p2) {
674 p1.swap(p2); 686 p1.swap(p2);
675 } 687 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 826
815 // A function to convert T* into scoped_ptr<T> 827 // A function to convert T* into scoped_ptr<T>
816 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation 828 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation
817 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) 829 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
818 template <typename T> 830 template <typename T>
819 scoped_ptr<T> make_scoped_ptr(T* ptr) { 831 scoped_ptr<T> make_scoped_ptr(T* ptr) {
820 return scoped_ptr<T>(ptr); 832 return scoped_ptr<T>(ptr);
821 } 833 }
822 834
823 #endif // BASE_MEMORY_SCOPED_PTR_H_ 835 #endif // BASE_MEMORY_SCOPED_PTR_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698