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

Unified Diff: third_party/WebKit/Source/wtf/RefPtr.h

Issue 1891473002: WTF: Implement explicit RefPtr::operator bool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
Index: third_party/WebKit/Source/wtf/RefPtr.h
diff --git a/third_party/WebKit/Source/wtf/RefPtr.h b/third_party/WebKit/Source/wtf/RefPtr.h
index 4ed3ea5de07c16ca00103e0044387d07421dbaef..1660f882f8b321cf8ee9605558c5af12319ffe17 100644
--- a/third_party/WebKit/Source/wtf/RefPtr.h
+++ b/third_party/WebKit/Source/wtf/RefPtr.h
@@ -70,11 +70,7 @@ public:
ALWAYS_INLINE T* operator->() const { return m_ptr; }
bool operator!() const { return !m_ptr; }
-
- // This conversion operator allows implicit conversion to bool but not to
- // other integer types.
- typedef T* (RefPtr::*UnspecifiedBoolType);
- operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; }
+ explicit operator bool() const { return m_ptr; }
RefPtr& operator=(RefPtr o) { swap(o); return *this; }
RefPtr& operator=(std::nullptr_t) { clear(); return *this; }
@@ -135,6 +131,16 @@ template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>&
return a == b.get();
}
+template <typename T> inline bool operator==(const RefPtr<T>& a, std::nullptr_t)
+{
+ return !a.get();
+}
+
+template <typename T> inline bool operator==(std::nullptr_t, const RefPtr<T>& b)
+{
+ return !b.get();
+}
+
template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
{
return a.get() != b.get();
@@ -150,6 +156,16 @@ template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>&
return a != b.get();
}
+template <typename T> inline bool operator!=(const RefPtr<T>& a, std::nullptr_t)
+{
+ return a.get();
+}
+
+template <typename T> inline bool operator!=(std::nullptr_t, const RefPtr<T>& b)
+{
+ return b.get();
+}
+
template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
{
return RefPtr<T>(static_cast<T*>(p.get()));
« no previous file with comments | « third_party/WebKit/Source/wtf/PassRefPtr.h ('k') | third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698