diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-08 21:38:47 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-08 21:38:47 +0200 |
commit | d69fd87b5038850dc554bc6f536aa5d82a38f4e4 (patch) | |
tree | a7d273e2cb5428086e0ca35086fbc407637e5cfa /AK | |
parent | 788293ead831512863e2c6000d2640536fe47e47 (diff) | |
download | serenity-d69fd87b5038850dc554bc6f536aa5d82a38f4e4.zip |
AK: Add templated NonnullOwnPtr::release_nonnull()
This allows you to release a NonnullOwnPtr<T> into a NonnullOwnPtr<U>
Diffstat (limited to 'AK')
-rw-r--r-- | AK/NonnullOwnPtr.h | 7 |
1 files changed, 7 insertions, 0 deletions
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<typename U> + NonnullOwnPtr<U> release_nonnull() + { + ASSERT(m_ptr); + return NonnullOwnPtr<U>(NonnullOwnPtr<U>::Adopt, static_cast<U&>(*leak_ptr())); + } + private: void clear() { |