mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:57:35 +00:00
AK: Convert the try_make<T> factory function to use ErrorOr
This allows more ergonomic memory allocation failure related error checking using the TRY macro.
This commit is contained in:
parent
ba0a2a3e2f
commit
18b98f8c28
2 changed files with 8 additions and 7 deletions
|
@ -215,17 +215,17 @@ inline ErrorOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object)
|
|||
}
|
||||
|
||||
template<typename T, class... Args>
|
||||
requires(IsConstructible<T, Args...>) inline OwnPtr<T> try_make(Args&&... args)
|
||||
requires(IsConstructible<T, Args...>) inline ErrorOr<NonnullOwnPtr<T>> try_make(Args&&... args)
|
||||
{
|
||||
return adopt_own_if_nonnull(new (nothrow) T(forward<Args>(args)...));
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) T(forward<Args>(args)...));
|
||||
}
|
||||
|
||||
// FIXME: Remove once P0960R3 is available in Clang.
|
||||
template<typename T, class... Args>
|
||||
inline OwnPtr<T> try_make(Args&&... args)
|
||||
inline ErrorOr<NonnullOwnPtr<T>> try_make(Args&&... args)
|
||||
|
||||
{
|
||||
return adopt_own_if_nonnull(new (nothrow) T { forward<Args>(args)... });
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) T { forward<Args>(args)... });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue