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

Add Vector::remove().

This commit is contained in:
Andreas Kling 2018-10-13 01:17:36 +02:00
parent 750b27cb07
commit 7777c8844b
2 changed files with 47 additions and 2 deletions

View file

@ -29,6 +29,18 @@ public:
T& at(unsigned i) { return *slot(i); }
const T& at(unsigned i) const { return *slot(i); }
void remove(unsigned index)
{
ASSERT(index < m_size);
at(index).~T();
for (unsigned i = index + 1; i < m_size; ++i) {
new (slot(i - 1)) T(std::move(at(i)));
at(i).~T();
}
--m_size;
}
private:
friend class Vector<T>;
@ -95,6 +107,11 @@ public:
return value;
}
void remove(unsigned index)
{
m_impl->remove(index);
}
void append(T&& value)
{
ensureCapacity(size() + 1);
@ -152,8 +169,8 @@ public:
unsigned m_index { 0 };
};
ConstIterator begin() const { return Iterator(*this, 0); }
ConstIterator end() const { return Iterator(*this, size()); }
ConstIterator begin() const { return ConstIterator(*this, 0); }
ConstIterator end() const { return ConstIterator(*this, size()); }
private:
static unsigned paddedCapacity(unsigned capacity)