mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:57:34 +00:00
AK: Move adopt_nonnull_own_or_enomem() to NonnullOwnPtr.h
Rewrite the implementation to not depend on OwnPtr.h. No intended behavior change.
This commit is contained in:
parent
cf73e15dc1
commit
ca6090889a
2 changed files with 10 additions and 10 deletions
|
@ -161,6 +161,15 @@ inline NonnullOwnPtr<T> make(Args&&... args)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Use like `adopt_nonnull_own_or_enomem(new (nothrow) T(args...))`.
|
||||||
|
template<typename T>
|
||||||
|
inline ErrorOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object)
|
||||||
|
{
|
||||||
|
if (!object)
|
||||||
|
return Error::from_errno(ENOMEM);
|
||||||
|
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, *object);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Traits<NonnullOwnPtr<T>> : public GenericTraits<NonnullOwnPtr<T>> {
|
struct Traits<NonnullOwnPtr<T>> : public GenericTraits<NonnullOwnPtr<T>> {
|
||||||
using PeekType = T*;
|
using PeekType = T*;
|
||||||
|
@ -190,5 +199,6 @@ struct Formatter<NonnullOwnPtr<T>> : Formatter<T const*> {
|
||||||
using AK::adopt_own;
|
using AK::adopt_own;
|
||||||
using AK::make;
|
using AK::make;
|
||||||
# endif
|
# endif
|
||||||
|
using AK::adopt_nonnull_own_or_enomem;
|
||||||
using AK::NonnullOwnPtr;
|
using AK::NonnullOwnPtr;
|
||||||
#endif
|
#endif
|
||||||
|
|
10
AK/OwnPtr.h
10
AK/OwnPtr.h
|
@ -192,15 +192,6 @@ inline OwnPtr<T> adopt_own_if_nonnull(T* object)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline ErrorOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object)
|
|
||||||
{
|
|
||||||
auto result = adopt_own_if_nonnull(object);
|
|
||||||
if (!result)
|
|
||||||
return Error::from_errno(ENOMEM);
|
|
||||||
return result.release_nonnull();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, class... Args>
|
template<typename T, class... Args>
|
||||||
requires(IsConstructible<T, Args...>) inline ErrorOr<NonnullOwnPtr<T>> try_make(Args&&... args)
|
requires(IsConstructible<T, Args...>) inline ErrorOr<NonnullOwnPtr<T>> try_make(Args&&... args)
|
||||||
{
|
{
|
||||||
|
@ -226,7 +217,6 @@ struct Traits<OwnPtr<T>> : public GenericTraits<OwnPtr<T>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USING_AK_GLOBALLY
|
#if USING_AK_GLOBALLY
|
||||||
using AK::adopt_nonnull_own_or_enomem;
|
|
||||||
using AK::adopt_own_if_nonnull;
|
using AK::adopt_own_if_nonnull;
|
||||||
using AK::OwnPtr;
|
using AK::OwnPtr;
|
||||||
using AK::try_make;
|
using AK::try_make;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue