diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 2df91099870..7c56b287e8f 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -14,6 +14,7 @@ # include # include +# include # include # include # include @@ -347,6 +348,15 @@ inline RefPtr try_make_ref_counted(Args&&... args) return adopt_ref_if_nonnull(new (nothrow) T { forward(args)... }); } +template +inline ErrorOr> adopt_nonnull_ref_or_enomem(T* object) +{ + auto result = adopt_ref_if_nonnull(object); + if (!result) + return ENOMEM; + return result.release_nonnull(); +} + } using AK::adopt_ref_if_nonnull;