diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index 416af312e2b..e6d62c6507e 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -191,6 +191,14 @@ inline void swap(OwnPtr& a, OwnPtr& b) a.swap(b); } +template +inline OwnPtr adopt_own_if_nonnull(T* object) +{ + if (object) + return OwnPtr(object); + return {}; +} + template struct Traits> : public GenericTraits> { using PeekType = T*; @@ -201,4 +209,5 @@ struct Traits> : public GenericTraits> { } +using AK::adopt_own_if_nonnull; using AK::OwnPtr;