AK: Add const_cast escape hatch for converting const T& to RefPtr<T>

There are parts of the codebase where properly const-correctifying the
the code would be a giant spaghetti mess, so add this loud workaround
to defer the refactoring for later.
This commit is contained in:
Andrew Kaster 2025-04-15 15:56:58 -06:00 committed by Andrew Kaster
parent 6ff0373556
commit 703abac9c8
Notes: github-actions[bot] 2025-04-16 16:43:38 +00:00

View file

@ -312,6 +312,24 @@ inline RefPtr<T> static_ptr_cast(RefPtr<U> const& ptr)
return RefPtr<T>(static_cast<T const*>(ptr.ptr()));
}
template<typename T>
inline NonnullRefPtr<T> fixme_launder_const_through_pointer_cast(NonnullRefPtr<T const> const& ptr)
{
return NonnullRefPtr<T>(const_cast<T&>(*ptr));
}
template<typename T>
inline RefPtr<T> fixme_launder_const_through_pointer_cast(RefPtr<T const> const& ptr)
{
return RefPtr<T>(const_cast<T*>(ptr.ptr()));
}
template<typename T>
inline NonnullRefPtr<T> fixme_launder_const_through_pointer_cast(T const& ptr)
{
return NonnullRefPtr<T>(const_cast<T&>(ptr));
}
template<typename T, typename U>
requires(IsConvertible<U*, T*>)
inline void swap(RefPtr<T>& a, RefPtr<U>& b)