Переглянути джерело

AK: Add equality operators to compare RefPtr to NonNullRefPtr

Allan Regush 3 роки тому
батько
коміт
63d06458ca
1 змінених файлів з 12 додано та 0 видалено
  1. 12 0
      AK/RefPtr.h

+ 12 - 0
AK/RefPtr.h

@@ -32,6 +32,8 @@ class [[nodiscard]] RefPtr {
     friend class RefPtr;
     template<typename U>
     friend class WeakPtr;
+    template<typename U>
+    friend class NonnullRefPtr;
 
 public:
     enum AdoptTag {
@@ -270,6 +272,16 @@ public:
     bool operator==(RefPtr& other) { return as_ptr() == other.as_ptr(); }
     bool operator!=(RefPtr& other) { return as_ptr() != other.as_ptr(); }
 
+    template<typename U>
+    bool operator==(NonnullRefPtr<U> const& other) const { return as_ptr() == other.m_ptr; }
+    template<typename U>
+    bool operator!=(NonnullRefPtr<U> const& other) const { return as_ptr() != other.m_ptr; }
+
+    template<typename U>
+    bool operator==(NonnullRefPtr<U>& other) { return as_ptr() == other.m_ptr; }
+    template<typename U>
+    bool operator!=(NonnullRefPtr<U>& other) { return as_ptr() != other.m_ptr; }
+
     bool operator==(const T* other) const { return as_ptr() == other; }
     bool operator!=(const T* other) const { return as_ptr() != other; }