mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
AK: Move try_make_ref_counted() to NonnullRefPtr.h
This commit is contained in:
parent
3c842d9d76
commit
0c4bbf5be3
Notes:
sideshowbarker
2024-07-17 10:05:47 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/0c4bbf5be3 Pull-request: https://github.com/SerenityOS/serenity/pull/17431 Reviewed-by: https://github.com/trflynn89 ✅
@ -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
|
||||
|
14
AK/RefPtr.h
14
AK/RefPtr.h
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user