AK: Move try_make() to NonnullOwnPtr.h

This commit is contained in:
Nico Weber 2023-02-11 06:36:18 -05:00 committed by Tim Flynn
parent 6bc6085219
commit 3c842d9d76
Notes: sideshowbarker 2024-07-17 00:31:28 +09:00
2 changed files with 15 additions and 15 deletions

View file

@ -170,6 +170,20 @@ inline ErrorOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object)
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, *object);
}
template<typename T, class... Args>
requires(IsConstructible<T, Args...>) inline ErrorOr<NonnullOwnPtr<T>> try_make(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 ErrorOr<NonnullOwnPtr<T>> try_make(Args&&... args)
{
return adopt_nonnull_own_or_enomem(new (nothrow) T { forward<Args>(args)... });
}
template<typename T>
struct Traits<NonnullOwnPtr<T>> : public GenericTraits<NonnullOwnPtr<T>> {
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

View file

@ -192,20 +192,6 @@ inline OwnPtr<T> adopt_own_if_nonnull(T* object)
return {};
}
template<typename T, class... Args>
requires(IsConstructible<T, Args...>) inline ErrorOr<NonnullOwnPtr<T>> try_make(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 ErrorOr<NonnullOwnPtr<T>> try_make(Args&&... args)
{
return adopt_nonnull_own_or_enomem(new (nothrow) T { forward<Args>(args)... });
}
template<typename T>
struct Traits<OwnPtr<T>> : public GenericTraits<OwnPtr<T>> {
using PeekType = T*;
@ -219,5 +205,4 @@ struct Traits<OwnPtr<T>> : public GenericTraits<OwnPtr<T>> {
#if USING_AK_GLOBALLY
using AK::adopt_own_if_nonnull;
using AK::OwnPtr;
using AK::try_make;
#endif