mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:37:34 +00:00
AK: Make smart pointer factories work with aggregates
Aggregate initialization with brace-enclosed parameters is a [C++20 feature][1] not yet implemented by Clang. This caused compile errors if we tried to use the factory functions to create smart pointers to aggregates. As a (temporary) fix, [the LWG's previously proposed solution][2] is implemented by this commit. Now, wherever it's not possible to direct-initialize, aggregate initialization is performed. [1]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html [2]: http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#2089
This commit is contained in:
parent
fda9f394d1
commit
3c6bdb8a61
5 changed files with 37 additions and 4 deletions
|
@ -486,11 +486,18 @@ inline RefPtr<T> adopt_ref_if_nonnull(T* object)
|
|||
}
|
||||
|
||||
template<typename T, class... Args>
|
||||
inline RefPtr<T> try_create(Args&&... args)
|
||||
requires(IsConstructible<T, Args...>) inline RefPtr<T> try_create(Args&&... args)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new (nothrow) T(forward<Args>(args)...));
|
||||
}
|
||||
|
||||
// FIXME: Remove once P0960R3 is available in Clang.
|
||||
template<typename T, class... Args>
|
||||
inline RefPtr<T> try_create(Args&&... args)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new (nothrow) T { forward<Args>(args)... });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::adopt_ref_if_nonnull;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue