summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-12-21 23:21:09 -0700
committerAndreas Kling <kling@serenityos.org>2021-01-17 20:30:31 +0100
commit7581b64705ed3c5b3711c956504f278c2ea3899e (patch)
treea98ad235a0166444f660fbc14ccc2975d742ff62 /AK
parentb17a889320cb2d3454e15920e9a6c4a242c476f0 (diff)
downloadserenity-7581b64705ed3c5b3711c956504f278c2ea3899e.zip
AK: Add Vector::remove overload for removing entire ranges
Diffstat (limited to 'AK')
-rw-r--r--AK/Vector.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/AK/Vector.h b/AK/Vector.h
index 8ea8042852..6e7f5b1886 100644
--- a/AK/Vector.h
+++ b/AK/Vector.h
@@ -257,6 +257,27 @@ public:
--m_size;
}
+ void remove(size_t index, size_t count)
+ {
+ if (count == 0)
+ return;
+ ASSERT(index + count > index);
+ ASSERT(index + count <= m_size);
+
+ if constexpr (Traits<T>::is_trivial()) {
+ TypedTransfer<T>::copy(slot(index), slot(index + count), m_size - index - count);
+ } else {
+ for (size_t i = index; i < index + count; i++)
+ at(i).~T();
+ for (size_t i = index + count; i < m_size; ++i) {
+ new (slot(i - count)) T(move(at(i)));
+ at(i).~T();
+ }
+ }
+
+ m_size -= count;
+ }
+
void insert(size_t index, T&& value)
{
ASSERT(index <= size());