From 79ce75d862000d6d26f0d7507f9803acb5795d98 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 1 Aug 2019 15:35:45 +0200 Subject: [PATCH] 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. :^) --- AK/Vector.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AK/Vector.h b/AK/Vector.h index c5c857aa63e..13592d017f9 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -326,6 +326,14 @@ public: unchecked_append(T(value)); } + template + void empend(Args&&... args) + { + grow_capacity(m_size + 1); + new (slot(m_size)) T(forward(args)...); + ++m_size; + } + void append(T&& value) { grow_capacity(size() + 1);