Index: base/memory/scoped_ptr.h |
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h |
index fab6c7e33f6546631d64b89719df2f8bada1e69c..44e20a5f29ae8815625727e24290faf348f66eaa 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 convertable to a real bool (which is dangerous). |
willchan no longer on Chromium
2012/10/05 22:19:13
s/convertable/convertible/
enne (OOO)
2012/10/06 02:18:41
Done. *blush*
|
+ typedef C* scoped_ptr::*testable; |
willchan no longer on Chromium
2012/10/05 22:19:13
Since testable is a type, please name it Testable.
enne (OOO)
2012/10/06 02:18:41
Done.
|
+ operator testable() const { return ptr_ ? &scoped_ptr::ptr_ : 0; } |
willchan no longer on Chromium
2012/10/05 22:19:13
We use NULL, a la Google C++ Style Guide.
enne (OOO)
2012/10/06 02:18:41
Done.
|
+ |
// 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 convertable to a real bool (which is dangerous). |
+ typedef C* scoped_array::*testable; |
+ operator testable() const { return array_ ? &scoped_array::array_ : 0; } |
+ |
// 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 convertable to a real bool (which is dangerous). |
+ typedef C* scoped_ptr_malloc::*testable; |
+ operator testable() const { return ptr_ ? &scoped_ptr_malloc::ptr_ : 0; } |
+ |
// 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. |