mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 01:37:35 +00:00
AK: Improve smart pointer ergonomics a bit.
This commit is contained in:
parent
d5dec1922b
commit
3f6408919f
17 changed files with 49 additions and 31 deletions
|
@ -53,6 +53,14 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
RetainPtr& operator=(Retained<U>&& other)
|
||||
{
|
||||
release_if_not_null(m_ptr);
|
||||
m_ptr = &other.leak_ref();
|
||||
return *this;
|
||||
}
|
||||
|
||||
RetainPtr& operator=(T* ptr)
|
||||
{
|
||||
if (m_ptr != ptr)
|
||||
|
@ -90,9 +98,6 @@ public:
|
|||
|
||||
bool operator!() const { return !m_ptr; }
|
||||
|
||||
typedef T* RetainPtr::*UnspecifiedBoolType;
|
||||
operator UnspecifiedBoolType() const { return m_ptr ? &RetainPtr::m_ptr : nullptr; }
|
||||
|
||||
T* leak_ref()
|
||||
{
|
||||
T* leakedPtr = m_ptr;
|
||||
|
@ -109,8 +114,20 @@ public:
|
|||
T& operator*() { return *m_ptr; }
|
||||
const T& operator*() const { return *m_ptr; }
|
||||
|
||||
operator const T*() const { return m_ptr; }
|
||||
operator T*() { return m_ptr; }
|
||||
|
||||
operator bool() { return !!m_ptr; }
|
||||
|
||||
bool operator==(std::nullptr_t) const { return !m_ptr; }
|
||||
bool operator!=(std::nullptr_t) const { return m_ptr; }
|
||||
|
||||
bool operator==(const RetainPtr& other) const { return m_ptr == other.m_ptr; }
|
||||
bool operator!=(const RetainPtr& other) const { return m_ptr != other.m_ptr; }
|
||||
|
||||
bool operator==(const T* other) const { return m_ptr == other; }
|
||||
bool operator!=(const T* other) const { return m_ptr != other; }
|
||||
|
||||
bool is_null() const { return !m_ptr; }
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue