1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:37:44 +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

@ -156,47 +156,27 @@ public:
return *ptr;
}
ALWAYS_INLINE RETURNS_NONNULL T* ptr()
{
return as_nonnull_ptr();
}
ALWAYS_INLINE RETURNS_NONNULL T const* ptr() const
ALWAYS_INLINE RETURNS_NONNULL T* ptr() const
{
return as_nonnull_ptr();
}
ALWAYS_INLINE RETURNS_NONNULL T* operator->()
{
return as_nonnull_ptr();
}
ALWAYS_INLINE RETURNS_NONNULL T const* operator->() const
ALWAYS_INLINE RETURNS_NONNULL T* operator->() const
{
return as_nonnull_ptr();
}
ALWAYS_INLINE T& operator*()
{
return *as_nonnull_ptr();
}
ALWAYS_INLINE T const& operator*() const
ALWAYS_INLINE T& operator*() const
{
return *as_nonnull_ptr();
}
ALWAYS_INLINE RETURNS_NONNULL operator T*()
{
return as_nonnull_ptr();
}
ALWAYS_INLINE RETURNS_NONNULL operator T const*() const
ALWAYS_INLINE RETURNS_NONNULL operator T*() const
{
return as_nonnull_ptr();
}
ALWAYS_INLINE operator T&()
{
return *as_nonnull_ptr();
}
ALWAYS_INLINE operator T const&() const
ALWAYS_INLINE operator T&() const
{
return *as_nonnull_ptr();
}
@ -217,7 +197,8 @@ public:
bool operator==(NonnullRefPtr const& other) const { return m_ptr == other.m_ptr; }
bool operator==(NonnullRefPtr& other) { return m_ptr == other.m_ptr; }
template<typename RawPtr>
bool operator==(RawPtr other) const requires(IsPointer<RawPtr>) { return m_ptr == other; }
// clang-format off
private: