mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Move try_make() to NonnullOwnPtr.h
This commit is contained in:
parent
6bc6085219
commit
3c842d9d76
Notes:
sideshowbarker
2024-07-17 00:31:28 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/3c842d9d76 Pull-request: https://github.com/SerenityOS/serenity/pull/17431 Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 15 additions and 15 deletions
|
@ -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
|
||||
|
|
15
AK/OwnPtr.h
15
AK/OwnPtr.h
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue