mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 01:59:31 +00: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: 0c4bbf5be3
Pull-request: https://github.com/SerenityOS/serenity/pull/17431
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 14 additions and 14 deletions
|
@ -235,6 +235,19 @@ inline ErrorOr<NonnullRefPtr<T>> adopt_nonnull_ref_or_enomem(T* object)
|
||||||
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, *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>
|
template<Formattable T>
|
||||||
struct Formatter<NonnullRefPtr<T>> : Formatter<T> {
|
struct Formatter<NonnullRefPtr<T>> : Formatter<T> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, NonnullRefPtr<T> const& value)
|
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::adopt_ref;
|
||||||
using AK::make_ref_counted;
|
using AK::make_ref_counted;
|
||||||
using AK::NonnullRefPtr;
|
using AK::NonnullRefPtr;
|
||||||
|
using AK::try_make_ref_counted;
|
||||||
#endif
|
#endif
|
||||||
|
|
14
AK/RefPtr.h
14
AK/RefPtr.h
|
@ -328,24 +328,10 @@ inline RefPtr<T> adopt_ref_if_nonnull(T* object)
|
||||||
return {};
|
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
|
#if USING_AK_GLOBALLY
|
||||||
using AK::adopt_ref_if_nonnull;
|
using AK::adopt_ref_if_nonnull;
|
||||||
using AK::RefPtr;
|
using AK::RefPtr;
|
||||||
using AK::static_ptr_cast;
|
using AK::static_ptr_cast;
|
||||||
using AK::try_make_ref_counted;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue