1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:47:35 +00:00

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
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)