1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:17:34 +00:00

OwnPtr: Add a way to turn an OwnPtr into a NonnullOwnPtr

Okay, so, OwnPtr<T>::release_nonnull() returns a NonnullOwnPtr<T>.
It assumes that the OwnPtr is non-null to begin with.

Note that this removes the value from the OwnPtr, as there can only be
a single owner.
This commit is contained in:
Andreas Kling 2019-08-14 11:02:49 +02:00
parent 99ed4ce30c
commit f75b1127b2
2 changed files with 23 additions and 0 deletions

View file

@ -120,6 +120,12 @@ public:
return leaked_ptr;
}
NonnullOwnPtr<T> release_nonnull()
{
ASSERT(m_ptr);
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, *leak_ptr());
}
T* ptr() { return m_ptr; }
const T* ptr() const { return m_ptr; }