mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
AK: Add Vector::empend().
This is a complement to append() that works by constructing the new element in-place via placement new and forwarded constructor arguments. The STL calls this emplace_back() which looks ugly, so I'm inventing a nice word for it instead. :^)
This commit is contained in:
parent
f4bae8971c
commit
79ce75d862
Notes:
sideshowbarker
2024-07-19 12:57:27 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/79ce75d8620
1 changed files with 8 additions and 0 deletions
|
@ -326,6 +326,14 @@ public:
|
|||
unchecked_append(T(value));
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
void empend(Args&&... args)
|
||||
{
|
||||
grow_capacity(m_size + 1);
|
||||
new (slot(m_size)) T(forward<Args>(args)...);
|
||||
++m_size;
|
||||
}
|
||||
|
||||
void append(T&& value)
|
||||
{
|
||||
grow_capacity(size() + 1);
|
||||
|
|
Loading…
Add table
Reference in a new issue