mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +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: 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/Iterator.h>
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
#include <AK/kmalloc.h>
|
#include <AK/kmalloc.h>
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -21,6 +22,17 @@ class FixedArray {
|
||||||
public:
|
public:
|
||||||
FixedArray() = default;
|
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)
|
static ErrorOr<FixedArray<T>> try_create(size_t size)
|
||||||
{
|
{
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue