mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:37:34 +00:00
Kernel: Convert try_make_ref_counted to use ErrorOr
This allows more ergonomic memory allocation failure related error checking using the TRY macro.
This commit is contained in:
parent
8289727fac
commit
a65bbbdb71
4 changed files with 14 additions and 15 deletions
|
@ -486,16 +486,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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue