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

Unified Diff: base/memory/scoped_ptr.h

Issue 11028044: Allow scoped_ptr variables to be used in boolean expressions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/scoped_ptr.h
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h
index fab6c7e33f6546631d64b89719df2f8bada1e69c..09981d88533ee3cac495829c966b101891950f5b 100644
--- a/base/memory/scoped_ptr.h
+++ b/base/memory/scoped_ptr.h
@@ -203,6 +203,11 @@ class scoped_ptr {
}
C* get() const { return ptr_; }
+ // Allow scoped_ptr<C> to be used in boolean expressions, but not
+ // implicitly convertible to a real bool (which is dangerous).
+ typedef C* scoped_ptr::*Testable;
+ operator Testable() const { return ptr_ ? &scoped_ptr::ptr_ : NULL; }
+
// Comparison operators.
// These return whether two scoped_ptr refer to the same object, not just to
// two different but equal objects.
@@ -328,6 +333,11 @@ class scoped_array {
return array_;
}
+ // Allow scoped_array<C> to be used in boolean expressions, but not
+ // implicitly convertible to a real bool (which is dangerous).
+ typedef C* scoped_array::*Testable;
+ operator Testable() const { return array_ ? &scoped_array::array_ : NULL; }
+
// Comparison operators.
// These return whether two scoped_array refer to the same object, not just to
// two different but equal objects.
@@ -451,6 +461,11 @@ class scoped_ptr_malloc {
return ptr_;
}
+ // Allow scoped_ptr_malloc<C> to be used in boolean expressions, but not
+ // implicitly convertible to a real bool (which is dangerous).
+ typedef C* scoped_ptr_malloc::*Testable;
+ operator Testable() const { return ptr_ ? &scoped_ptr_malloc::ptr_ : NULL; }
+
// Comparison operators.
// These return whether a scoped_ptr_malloc and a plain pointer refer
// to the same object, not just to two different but equal objects.
« 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