summaryrefslogtreecommitdiff
path: root/AK/RefPtr.h
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-02-03 16:43:34 +0200
committerAndreas Kling <kling@serenityos.org>2022-02-03 23:33:20 +0100
commita65bbbdb71d68f731b24fd816c6c140fbf5c41af (patch)
tree48a4c37ea0b661079a44d11bd7bc8348f2f764d2 /AK/RefPtr.h
parent8289727fac65688ae8df8859743516f3dee2ed9a (diff)
downloadserenity-a65bbbdb71d68f731b24fd816c6c140fbf5c41af.zip
Kernel: Convert try_make_ref_counted to use ErrorOr
This allows more ergonomic memory allocation failure related error checking using the TRY macro.
Diffstat (limited to 'AK/RefPtr.h')
-rw-r--r--AK/RefPtr.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/AK/RefPtr.h b/AK/RefPtr.h
index 5d3acff198..3696082e14 100644
--- a/AK/RefPtr.h
+++ b/AK/RefPtr.h
@@ -336,16 +336,16 @@ inline RefPtr<T> adopt_ref_if_nonnull(T* object)
}
template<typename T, class... Args>
-requires(IsConstructible<T, Args...>) inline RefPtr<T> try_make_ref_counted(Args&&... args)
+requires(IsConstructible<T, Args...>) inline ErrorOr<NonnullRefPtr<T>> try_make_ref_counted(Args&&... args)
{
- return adopt_ref_if_nonnull(new (nothrow) T(forward<Args>(args)...));
+ return adopt_nonnull_ref_or_enomem(new (nothrow) T(forward<Args>(args)...));
}
// FIXME: Remove once P0960R3 is available in Clang.
template<typename T, class... Args>
-inline RefPtr<T> try_make_ref_counted(Args&&... args)
+inline ErrorOr<NonnullRefPtr<T>> try_make_ref_counted(Args&&... args)
{
- return adopt_ref_if_nonnull(new (nothrow) T { forward<Args>(args)... });
+ return adopt_nonnull_ref_or_enomem(new (nothrow) T { forward<Args>(args)... });
}
template<typename T>