mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +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
1 changed files with 8 additions and 0 deletions
|
@ -326,6 +326,14 @@ public:
|
||||||
unchecked_append(T(value));
|
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)
|
void append(T&& value)
|
||||||
{
|
{
|
||||||
grow_capacity(size() + 1);
|
grow_capacity(size() + 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue