Index: base/memory/ref_counted.h |
diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h |
index 0c0e0afd770f4bb3f71d222b098d200c4e3688d4..100668ff1c6bb02ba7363c6e6e9c78ef0828de23 100644 |
--- a/base/memory/ref_counted.h |
+++ b/base/memory/ref_counted.h |
@@ -362,31 +362,12 @@ class scoped_refptr { |
swap(&r.ptr_); |
} |
+ explicit operator bool() const { return ptr_ != nullptr; } |
+ |
private: |
danakj
2016/05/10 21:37:46
There's no reason to make a private block for this
danakj
2016/05/10 21:38:51
(I'm also wondering why it's here, we're calling .
scheib
2016/05/10 22:25:00
Done, moved friend to bottom private section and c
|
template <typename U> friend class scoped_refptr; |
- // Implement "Safe Bool Idiom" |
- // https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool |
- // |
- // Allow scoped_refptr<T> to be used in boolean expressions such as |
- // if (ref_ptr_instance) |
- // But do not become convertible to a real bool (which is dangerous). |
- // Implementation requires: |
- // typedef Testable |
- // operator Testable() const |
- // operator== |
- // operator!= |
- // |
- // == and != operators must be declared explicitly or dissallowed, as |
- // otherwise "ptr1 == ptr2" will compile but do the wrong thing (i.e., convert |
- // to Testable and then do the comparison). |
- // |
- // C++11 provides for "explicit operator bool()", however it is currently |
- // banned due to MSVS2013. https://chromium-cpp.appspot.com/#core-blacklist |
- typedef T* scoped_refptr::*Testable; |
public: |
- operator Testable() const { return ptr_ ? &scoped_refptr::ptr_ : nullptr; } |
- |
template <typename U> |
bool operator==(const scoped_refptr<U>& rhs) const { |
return ptr_ == rhs.get(); |