AK: Add Vector::prepend().

This commit is contained in:
Andreas Kling 2019-04-16 03:47:24 +02:00
parent 73c70e5d2e
commit d31b47b371
Notes: sideshowbarker 2024-07-19 14:41:27 +09:00

View file

@ -222,6 +222,17 @@ public:
++m_impl->m_size; ++m_impl->m_size;
} }
void prepend(const T& value)
{
ensure_capacity(size() + 1);
for (int i = size(); i > 0; --i) {
new (m_impl->slot(i)) T(move(at(i - 1)));
at(i - 1).~T();
}
new (m_impl->slot(0)) T(value);
++m_impl->m_size;
}
void append(const T* values, int count) void append(const T* values, int count)
{ {
if (!count) if (!count)