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

AK: Add InitializerList, an implementation of std::initializer_list

Use the AK version of std::initializer_list in AK::Vector, but only
when in serenity. When building AK for a non-serenity target, the header
<initializer_list> should be always available.
This commit is contained in:
Andrew Kaster 2020-05-15 21:23:51 -06:00 committed by Andreas Kling
parent 3de808e860
commit 0a2cab0928
2 changed files with 78 additions and 10 deletions

View file

@ -33,15 +33,11 @@
#include <AK/Traits.h>
#include <AK/kmalloc.h>
// NOTE: We can't include <initializer_list> during the toolchain bootstrap,
// since it's part of libstdc++, and libstdc++ depends on LibC.
// For this reason, we don't support Vector(initializer_list) in LibC.
#ifndef SERENITY_LIBC_BUILD
# include <initializer_list>
#endif
#ifndef __serenity__
#ifdef __serenity__
# include <AK/InitializerList.h>
#else // !__serenity__
# include <new>
# include <initializer_list>
#endif
namespace AK {
@ -144,14 +140,12 @@ public:
clear();
}
#ifndef SERENITY_LIBC_BUILD
Vector(std::initializer_list<T> list)
{
ensure_capacity(list.size());
for (auto& item : list)
unchecked_append(item);
}
#endif
Vector(Vector&& other)
: m_size(other.m_size)