diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index 2c207e05ae7..5f9b516c4fc 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -170,6 +170,20 @@ inline ErrorOr> adopt_nonnull_own_or_enomem(T* object) return NonnullOwnPtr(NonnullOwnPtr::Adopt, *object); } +template +requires(IsConstructible) inline ErrorOr> try_make(Args&&... args) +{ + return adopt_nonnull_own_or_enomem(new (nothrow) T(forward(args)...)); +} + +// FIXME: Remove once P0960R3 is available in Clang. +template +inline ErrorOr> try_make(Args&&... args) + +{ + return adopt_nonnull_own_or_enomem(new (nothrow) T { forward(args)... }); +} + template struct Traits> : public GenericTraits> { using PeekType = T*; @@ -201,4 +215,5 @@ using AK::make; # endif using AK::adopt_nonnull_own_or_enomem; using AK::NonnullOwnPtr; +using AK::try_make; #endif diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index 3f8a61095b7..0dca19c3365 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -192,20 +192,6 @@ inline OwnPtr adopt_own_if_nonnull(T* object) return {}; } -template -requires(IsConstructible) inline ErrorOr> try_make(Args&&... args) -{ - return adopt_nonnull_own_or_enomem(new (nothrow) T(forward(args)...)); -} - -// FIXME: Remove once P0960R3 is available in Clang. -template -inline ErrorOr> try_make(Args&&... args) - -{ - return adopt_nonnull_own_or_enomem(new (nothrow) T { forward(args)... }); -} - template struct Traits> : public GenericTraits> { using PeekType = T*; @@ -219,5 +205,4 @@ struct Traits> : public GenericTraits> { #if USING_AK_GLOBALLY using AK::adopt_own_if_nonnull; using AK::OwnPtr; -using AK::try_make; #endif