AK: Add Vector::remove overload for removing entire ranges

This commit is contained in:
Tom 2020-12-21 23:21:09 -07:00 committed by Andreas Kling
parent b17a889320
commit 7581b64705
Notes: sideshowbarker 2024-07-18 23:08:14 +09:00

View file

@ -257,6 +257,27 @@ public:
--m_size;
}
void remove(size_t index, size_t count)
{
if (count == 0)
return;
ASSERT(index + count > index);
ASSERT(index + count <= m_size);
if constexpr (Traits<T>::is_trivial()) {
TypedTransfer<T>::copy(slot(index), slot(index + count), m_size - index - count);
} else {
for (size_t i = index; i < index + count; i++)
at(i).~T();
for (size_t i = index + count; i < m_size; ++i) {
new (slot(i - count)) T(move(at(i)));
at(i).~T();
}
}
m_size -= count;
}
void insert(size_t index, T&& value)
{
ASSERT(index <= size());