From 0c4bbf5be33546fb43a52c41359dc8064a195374 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 11 Feb 2023 06:37:21 -0500 Subject: [PATCH] AK: Move try_make_ref_counted() to NonnullRefPtr.h --- AK/NonnullRefPtr.h | 14 ++++++++++++++ AK/RefPtr.h | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 7be705bb3f7..107aedc4a9d 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -235,6 +235,19 @@ inline ErrorOr> adopt_nonnull_ref_or_enomem(T* object) return NonnullRefPtr(NonnullRefPtr::Adopt, *object); } +template +requires(IsConstructible) inline ErrorOr> try_make_ref_counted(Args&&... args) +{ + return adopt_nonnull_ref_or_enomem(new (nothrow) T(forward(args)...)); +} + +// FIXME: Remove once P0960R3 is available in Clang. +template +inline ErrorOr> try_make_ref_counted(Args&&... args) +{ + return adopt_nonnull_ref_or_enomem(new (nothrow) T { forward(args)... }); +} + template struct Formatter> : Formatter { ErrorOr format(FormatBuilder& builder, NonnullRefPtr 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 diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 528cf7c38c8..1c28a07d9a0 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -328,24 +328,10 @@ inline RefPtr adopt_ref_if_nonnull(T* object) return {}; } -template -requires(IsConstructible) inline ErrorOr> try_make_ref_counted(Args&&... args) -{ - return adopt_nonnull_ref_or_enomem(new (nothrow) T(forward(args)...)); -} - -// FIXME: Remove once P0960R3 is available in Clang. -template -inline ErrorOr> try_make_ref_counted(Args&&... args) -{ - return adopt_nonnull_ref_or_enomem(new (nothrow) T { forward(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