aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/include
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-03-26 18:04:12 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-03-27 07:02:35 +0100
commit4b094e2bd5a8e60ec1018d6aa90aa9da4adf49c9 (patch)
treef96ab182776f58d46a3cf47882855995de109a64 /libs/kstd/include
parentaa68f53d2502e0ea81c8e9c95e37d9847cb6cb16 (diff)
downloadteachos-4b094e2bd5a8e60ec1018d6aa90aa9da4adf49c9.tar.xz
teachos-4b094e2bd5a8e60ec1018d6aa90aa9da4adf49c9.zip
kstd/vector: implement single-element erase
Diffstat (limited to 'libs/kstd/include')
-rw-r--r--libs/kstd/include/kstd/vector16
1 files changed, 16 insertions, 0 deletions
diff --git a/libs/kstd/include/kstd/vector b/libs/kstd/include/kstd/vector
index 0d4aac8..74aefa9 100644
--- a/libs/kstd/include/kstd/vector
+++ b/libs/kstd/include/kstd/vector
@@ -690,6 +690,22 @@ namespace kstd
return begin() + prefix_size;
}
+ constexpr auto erase(const_iterator position) -> iterator
+ {
+ if (position == end())
+ {
+ os::panic("[kstd:vector] Attempted to erase end()!");
+ }
+
+ auto prefix_size = std::ranges::distance(cbegin(), position);
+
+ std::ranges::move(begin() + prefix_size + 1, end(), begin() + prefix_size);
+ std::allocator_traits<allocator_type>::destroy(m_allocator, end() - 1);
+ --m_size;
+
+ return begin() + prefix_size;
+ }
+
//! Append a given element to this vector via copy construction.
constexpr auto push_back(value_type const & value) -> void
{