mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
AK: Add Vector::prepend().
This commit is contained in:
parent
73c70e5d2e
commit
d31b47b371
Notes:
sideshowbarker
2024-07-19 14:41:27 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d31b47b371b
1 changed files with 11 additions and 0 deletions
11
AK/Vector.h
11
AK/Vector.h
|
@ -222,6 +222,17 @@ public:
|
|||
++m_impl->m_size;
|
||||
}
|
||||
|
||||
void prepend(const T& value)
|
||||
{
|
||||
ensure_capacity(size() + 1);
|
||||
for (int i = size(); i > 0; --i) {
|
||||
new (m_impl->slot(i)) T(move(at(i - 1)));
|
||||
at(i - 1).~T();
|
||||
}
|
||||
new (m_impl->slot(0)) T(value);
|
||||
++m_impl->m_size;
|
||||
}
|
||||
|
||||
void append(const T* values, int count)
|
||||
{
|
||||
if (!count)
|
||||
|
|
Loading…
Reference in a new issue