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

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

Issue 17028014: Disallow explicit scoped_ptr<T> construction from NULL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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<T>): 10 // Example usage (scoped_ptr<T>):
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 template <typename PassAsType> 425 template <typename PassAsType>
426 scoped_ptr<PassAsType> PassAs() { 426 scoped_ptr<PassAsType> PassAs() {
427 return scoped_ptr<PassAsType>(Pass()); 427 return scoped_ptr<PassAsType>(Pass());
428 } 428 }
429 429
430 private: 430 private:
431 // Needed to reach into |impl_| in the constructor. 431 // Needed to reach into |impl_| in the constructor.
432 template <typename U, typename V> friend class scoped_ptr; 432 template <typename U, typename V> friend class scoped_ptr;
433 base::internal::scoped_ptr_impl<element_type, deleter_type> impl_; 433 base::internal::scoped_ptr_impl<element_type, deleter_type> impl_;
434 434
435 // Forbidden for API compatibility with std::unique_ptr.
436 explicit scoped_ptr(int disallow_construction_from_null);
437
435 // Forbid comparison of scoped_ptr types. If U != T, it totally 438 // Forbid comparison of scoped_ptr types. If U != T, it totally
436 // doesn't make sense, and if U == T, it still doesn't make sense 439 // doesn't make sense, and if U == T, it still doesn't make sense
437 // because you should never have the same object owned by two different 440 // because you should never have the same object owned by two different
438 // scoped_ptrs. 441 // scoped_ptrs.
439 template <class U> bool operator==(scoped_ptr<U> const& p2) const; 442 template <class U> bool operator==(scoped_ptr<U> const& p2) const;
440 template <class U> bool operator!=(scoped_ptr<U> const& p2) const; 443 template <class U> bool operator!=(scoped_ptr<U> const& p2) const;
441 }; 444 };
442 445
443 template <class T, class D> 446 template <class T, class D>
444 class scoped_ptr<T[], D> { 447 class scoped_ptr<T[], D> {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 700
698 // A function to convert T* into scoped_ptr<T> 701 // A function to convert T* into scoped_ptr<T>
699 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation 702 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation
700 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) 703 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
701 template <typename T> 704 template <typename T>
702 scoped_ptr<T> make_scoped_ptr(T* ptr) { 705 scoped_ptr<T> make_scoped_ptr(T* ptr) {
703 return scoped_ptr<T>(ptr); 706 return scoped_ptr<T>(ptr);
704 } 707 }
705 708
706 #endif // BASE_MEMORY_SCOPED_PTR_H_ 709 #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