mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
AK: Move try_make_ref_counted() to NonnullRefPtr.h
This commit is contained in:
parent
3c842d9d76
commit
0c4bbf5be3
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