Vector: Add insert() overload that takes a const T&.

This commit is contained in:
Andreas Kling 2019-05-17 04:59:56 +02:00
parent cde47089d2
commit cc5ee3bff4
Notes: sideshowbarker 2024-07-19 14:05:11 +09:00

View file

@ -167,6 +167,20 @@ public:
new (slot(index)) T(move(value));
}
void insert(int index, const T& value)
{
ASSERT(index <= size());
if (index == size())
return append(value);
grow_capacity(size() + 1);
++m_size;
for (int i = size() - 1; i > index; --i) {
new (slot(i)) T(move(at(i - 1)));
at(i - 1).~T();
}
new (slot(index)) T(value);
}
Vector& operator=(const Vector& other)
{
if (this != &other) {