AK: Add Vector(std::initializer_list<T>) constructor.

This allows us to construct a Vector from an initializer list like so:

Vector<Object> objects = { object1, object2, object3 };
This commit is contained in:
Andreas Kling 2019-06-28 20:20:19 +02:00
parent 933cd3848f
commit 4c285f9e1a
Notes: sideshowbarker 2024-07-19 13:27:45 +09:00
2 changed files with 9 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include <AK/Assertions.h>
#include <AK/StdLibExtras.h>
#include <AK/kmalloc.h>
#include <initializer_list>
#ifndef __serenity__
#include <new>
@ -64,6 +65,13 @@ public:
clear();
}
Vector(std::initializer_list<T> list)
{
ensure_capacity(list.size());
for (auto& item : list)
unchecked_append(item);
}
Vector(Vector&& other)
: m_size(other.m_size)
, m_capacity(other.m_capacity)

View File

@ -92,7 +92,7 @@ OBJS = $(CXX_OBJS) Boot/boot.ao
KERNEL = kernel
CXXFLAGS += -ffreestanding -mregparm=3 -mno-80387 -mno-mmx -mno-sse -mno-sse2
CXXFLAGS += -nostdinc++ -nostdlib -nostdinc
CXXFLAGS += -nostdlib
DEFINES += -DKERNEL
LDFLAGS += -Ttext 0x10000 -Wl,-T linker.ld -nostdlib