AK: Add templated NonnullOwnPtr::release_nonnull()

This allows you to release a NonnullOwnPtr<T> into a NonnullOwnPtr<U>
This commit is contained in:
Andreas Kling 2020-05-08 21:38:47 +02:00
parent 788293ead8
commit d69fd87b50

View file

@ -155,6 +155,13 @@ public:
::swap(m_ptr, other.m_ptr);
}
template<typename U>
NonnullOwnPtr<U> release_nonnull()
{
ASSERT(m_ptr);
return NonnullOwnPtr<U>(NonnullOwnPtr<U>::Adopt, static_cast<U&>(*leak_ptr()));
}
private:
void clear()
{