1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:47:45 +00:00

AK: Return non-const types from Ptr class operators

Even if the pointer value is const, the value they point to is not
necessarily const, so these functions should not add the qualifier.

This also removes the redundant non-const implementations of these
operators.
This commit is contained in:
MacDue 2022-11-19 01:03:48 +00:00 committed by Linus Groh
parent 24caacfe28
commit 3483407ddc
5 changed files with 23 additions and 85 deletions

View file

@ -231,31 +231,19 @@ public:
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, *ptr);
}
ALWAYS_INLINE T* ptr() { return as_ptr(); }
ALWAYS_INLINE T const* ptr() const { return as_ptr(); }
ALWAYS_INLINE T* ptr() const { return as_ptr(); }
ALWAYS_INLINE T* operator->()
ALWAYS_INLINE T* operator->() const
{
return as_nonnull_ptr();
}
ALWAYS_INLINE T const* operator->() const
{
return as_nonnull_ptr();
}
ALWAYS_INLINE T& operator*()
ALWAYS_INLINE T& operator*() const
{
return *as_nonnull_ptr();
}
ALWAYS_INLINE T const& operator*() const
{
return *as_nonnull_ptr();
}
ALWAYS_INLINE operator T const*() const { return as_ptr(); }
ALWAYS_INLINE operator T*() { return as_ptr(); }
ALWAYS_INLINE operator T*() const { return as_ptr(); }
ALWAYS_INLINE operator bool() { return !is_null(); }
@ -263,17 +251,11 @@ public:
bool operator==(RefPtr const& other) const { 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>& other) { return as_ptr() == other.m_ptr; }
bool operator==(T const* other) const { return as_ptr() == other; }
bool operator==(T* other) { return as_ptr() == other; }
template<typename RawPtr>
bool operator==(RawPtr other) const requires(IsPointer<RawPtr>) { return as_ptr() == other; }
ALWAYS_INLINE bool is_null() const { return !m_ptr; }