diff --git a/AK/FixedArray.h b/AK/FixedArray.h index 8f0d1a9b418..92593e5ffaf 100644 --- a/AK/FixedArray.h +++ b/AK/FixedArray.h @@ -55,6 +55,19 @@ public: return FixedArray(N, elements); } + template + static ErrorOr> try_create(Span span) + { + if (span.size() == 0) + return FixedArray(); + T* elements = static_cast(kmalloc_array(span.size(), sizeof(T))); + if (!elements) + return Error::from_errno(ENOMEM); + for (size_t i = 0; i < span.size(); ++i) + new (&elements[i]) T(span[i]); + return FixedArray(span.size(), elements); + } + ErrorOr> try_clone() const { if (m_size == 0)