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. |