mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Allow creating a FixedArray from an initializer list
This commit is contained in:
parent
65f34504e9
commit
09df8f812a
Notes:
sideshowbarker
2024-07-17 18:11:56 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/09df8f812a Pull-request: https://github.com/SerenityOS/serenity/pull/12733
1 changed files with 12 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue