AK: Allow creating a FixedArray from an initializer list

This commit is contained in:
kleines Filmröllchen 2022-02-23 11:31:04 +01:00 committed by Ali Mohammad Pur
parent 65f34504e9
commit 09df8f812a
Notes: sideshowbarker 2024-07-17 18:11:56 +09:00

View file

@ -11,6 +11,7 @@
#include <AK/Iterator.h>
#include <AK/Span.h>
#include <AK/kmalloc.h>
#include <initializer_list>
namespace AK {
@ -21,6 +22,17 @@ class FixedArray {
public:
FixedArray() = default;
static ErrorOr<FixedArray<T>> try_create(std::initializer_list<T> initializer)
{
auto array = TRY(try_create(initializer.size()));
auto it = initializer.begin();
for (size_t i = 0; i < array.size(); ++i) {
array[i] = move(*it);
++it;
}
return array;
}
static ErrorOr<FixedArray<T>> try_create(size_t size)
{
if (size == 0)