summaryrefslogtreecommitdiff
path: root/AK/RefPtr.h
diff options
context:
space:
mode:
Diffstat (limited to 'AK/RefPtr.h')
-rw-r--r--AK/RefPtr.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/AK/RefPtr.h b/AK/RefPtr.h
index 2df9109987..7c56b287e8 100644
--- a/AK/RefPtr.h
+++ b/AK/RefPtr.h
@@ -14,6 +14,7 @@
# include <AK/Assertions.h>
# include <AK/Atomic.h>
+# include <AK/Error.h>
# include <AK/Format.h>
# include <AK/NonnullRefPtr.h>
# include <AK/StdLibExtras.h>
@@ -347,6 +348,15 @@ inline RefPtr<T> try_make_ref_counted(Args&&... args)
return adopt_ref_if_nonnull(new (nothrow) T { forward<Args>(args)... });
}
+template<typename T>
+inline ErrorOr<NonnullRefPtr<T>> 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;