AK: Move try_make_ref_counted() to NonnullRefPtr.h

This commit is contained in:
Nico Weber 2023-02-11 06:37:21 -05:00 committed by Tim Flynn
parent 3c842d9d76
commit 0c4bbf5be3
Notes: sideshowbarker 2024-07-17 10:05:47 +09:00
2 changed files with 14 additions and 14 deletions

View File

@ -235,6 +235,19 @@ inline ErrorOr<NonnullRefPtr<T>> adopt_nonnull_ref_or_enomem(T* object)
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, *object);
}
template<typename T, class... Args>
requires(IsConstructible<T, Args...>) inline ErrorOr<NonnullRefPtr<T>> try_make_ref_counted(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 ErrorOr<NonnullRefPtr<T>> try_make_ref_counted(Args&&... args)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) T { forward<Args>(args)... });
}
template<Formattable T>
struct Formatter<NonnullRefPtr<T>> : Formatter<T> {
ErrorOr<void> format(FormatBuilder& builder, NonnullRefPtr<T> const& value)
@ -287,4 +300,5 @@ using AK::adopt_nonnull_ref_or_enomem;
using AK::adopt_ref;
using AK::make_ref_counted;
using AK::NonnullRefPtr;
using AK::try_make_ref_counted;
#endif

View File

@ -328,24 +328,10 @@ inline RefPtr<T> adopt_ref_if_nonnull(T* object)
return {};
}
template<typename T, class... Args>
requires(IsConstructible<T, Args...>) inline ErrorOr<NonnullRefPtr<T>> try_make_ref_counted(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 ErrorOr<NonnullRefPtr<T>> try_make_ref_counted(Args&&... args)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) T { forward<Args>(args)... });
}
}
#if USING_AK_GLOBALLY
using AK::adopt_ref_if_nonnull;
using AK::RefPtr;
using AK::static_ptr_cast;
using AK::try_make_ref_counted;
#endif