diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-07 10:35:13 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-07 10:35:13 +0100 |
commit | 6a8695e7592177b9c952d9db3dfdeccb2a4dd973 (patch) | |
tree | e8939634e50c33ea1a21c44ae60b9ca922f96341 /AK | |
parent | a377e8d3f53c1622820eb152e1920428e6fa6be6 (diff) | |
download | serenity-6a8695e7592177b9c952d9db3dfdeccb2a4dd973.zip |
AK: Add Vector::prepend(T&&)
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Vector.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/AK/Vector.h b/AK/Vector.h index 22d1692afb..76c96d05b8 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -385,15 +385,14 @@ public: append(T(value)); } + void prepend(T&& value) + { + insert(0, move(value)); + } + void prepend(const T& value) { - grow_capacity(size() + 1); - for (int i = size(); i > 0; --i) { - new (slot(i)) T(move(at(i - 1))); - at(i - 1).~T(); - } - new (slot(0)) T(value); - ++m_size; + insert(0, value); } void prepend(Vector&& other) |