mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
Vector: Add insert() overload that takes a const T&.
This commit is contained in:
parent
cde47089d2
commit
cc5ee3bff4
Notes:
sideshowbarker
2024-07-19 14:05:11 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/cc5ee3bff4a
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
Reference in a new issue