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:
Andreas Kling 2019-08-01 15:35:45 +02:00
parent f4bae8971c
commit 79ce75d862

View file

@ -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);