From d69fd87b5038850dc554bc6f536aa5d82a38f4e4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 8 May 2020 21:38:47 +0200 Subject: [PATCH] AK: Add templated NonnullOwnPtr::release_nonnull() This allows you to release a NonnullOwnPtr into a NonnullOwnPtr --- AK/NonnullOwnPtr.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index ddf2c6e50d..5b9dc53e49 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -155,6 +155,13 @@ public: ::swap(m_ptr, other.m_ptr); } + template + NonnullOwnPtr release_nonnull() + { + ASSERT(m_ptr); + return NonnullOwnPtr(NonnullOwnPtr::Adopt, static_cast(*leak_ptr())); + } + private: void clear() {