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

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

Issue 1340683002: Remove base's implicit_cast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // Constructor. Stores the given array. Note that the argument's type 458 // Constructor. Stores the given array. Note that the argument's type
459 // must exactly match T*. In particular: 459 // must exactly match T*. In particular:
460 // - it cannot be a pointer to a type derived from T, because it is 460 // - it cannot be a pointer to a type derived from T, because it is
461 // inherently unsafe in the general case to access an array through a 461 // inherently unsafe in the general case to access an array through a
462 // pointer whose dynamic type does not match its static type (eg., if 462 // pointer whose dynamic type does not match its static type (eg., if
463 // T and the derived types had different sizes access would be 463 // T and the derived types had different sizes access would be
464 // incorrectly calculated). Deletion is also always undefined 464 // incorrectly calculated). Deletion is also always undefined
465 // (C++98 [expr.delete]p3). If you're doing this, fix your code. 465 // (C++98 [expr.delete]p3). If you're doing this, fix your code.
466 // - it cannot be const-qualified differently from T per unique_ptr spec 466 // - it cannot be const-qualified differently from T per unique_ptr spec
467 // (http://cplusplus.github.com/LWG/lwg-active.html#2118). Users wanting 467 // (http://cplusplus.github.com/LWG/lwg-active.html#2118). Users wanting
468 // to work around this may use implicit_cast<const T*>(). 468 // to work around this may use static_cast<const T*>().
469 // However, because of the first bullet in this comment, users MUST 469 // However, because of the first bullet in this comment, users MUST
470 // NOT use implicit_cast<Base*>() to upcast the static type of the array. 470 // NOT use static_cast<Base*>() to upcast the static type of the array.
danakj 2015/09/11 20:44:20 I'm not sure this is really the right way to say t
Nico 2015/09/11 20:53:54 This probably needs const_cast?
danakj 2015/09/11 21:20:28 Ah yah, ok changed both to const_cast in the comme
471 explicit scoped_ptr(element_type* array) : impl_(array) {} 471 explicit scoped_ptr(element_type* array) : impl_(array) {}
472 472
473 // Constructor. Allows construction from a nullptr. 473 // Constructor. Allows construction from a nullptr.
474 scoped_ptr(decltype(nullptr)) : impl_(nullptr) {} 474 scoped_ptr(decltype(nullptr)) : impl_(nullptr) {}
475 475
476 // Constructor. Allows construction from a scoped_ptr rvalue. 476 // Constructor. Allows construction from a scoped_ptr rvalue.
477 scoped_ptr(scoped_ptr&& other) : impl_(&other.impl_) {} 477 scoped_ptr(scoped_ptr&& other) : impl_(&other.impl_) {}
478 478
479 // operator=. Allows assignment from a scoped_ptr rvalue. 479 // operator=. Allows assignment from a scoped_ptr rvalue.
480 scoped_ptr& operator=(scoped_ptr&& rhs) { 480 scoped_ptr& operator=(scoped_ptr&& rhs) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 scoped_ptr<T> make_scoped_ptr(T* ptr) { 585 scoped_ptr<T> make_scoped_ptr(T* ptr) {
586 return scoped_ptr<T>(ptr); 586 return scoped_ptr<T>(ptr);
587 } 587 }
588 588
589 template <typename T> 589 template <typename T>
590 std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) { 590 std::ostream& operator<<(std::ostream& out, const scoped_ptr<T>& p) {
591 return out << p.get(); 591 return out << p.get();
592 } 592 }
593 593
594 #endif // BASE_MEMORY_SCOPED_PTR_H_ 594 #endif // BASE_MEMORY_SCOPED_PTR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698