diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-17 04:59:56 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-17 04:59:56 +0200 |
commit | cc5ee3bff4ad1ed9fe8cc0797a8e81d0f05c0743 (patch) | |
tree | afb7a21262a93fd7cd5ae8658b8991eae48c734a /AK | |
parent | cde47089d2276c9ec8b0e818850f45f54cf6418b (diff) | |
download | serenity-cc5ee3bff4ad1ed9fe8cc0797a8e81d0f05c0743.zip |
Vector: Add insert() overload that takes a const T&.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Vector.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/AK/Vector.h b/AK/Vector.h index 5639ca7aa9..f3474b0ee8 100644 --- a/AK/Vector.h +++ b/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) { |