mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
Vector: Add insert() overload that takes a const T&.
This commit is contained in:
parent
cde47089d2
commit
cc5ee3bff4
1 changed files with 14 additions and 0 deletions
14
AK/Vector.h
14
AK/Vector.h
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue