summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-05-17 04:59:56 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-05-17 04:59:56 +0200
commitcc5ee3bff4ad1ed9fe8cc0797a8e81d0f05c0743 (patch)
treeafb7a21262a93fd7cd5ae8658b8991eae48c734a /AK
parentcde47089d2276c9ec8b0e818850f45f54cf6418b (diff)
downloadserenity-cc5ee3bff4ad1ed9fe8cc0797a8e81d0f05c0743.zip
Vector: Add insert() overload that takes a const T&.
Diffstat (limited to 'AK')
-rw-r--r--AK/Vector.h14
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) {