From a58275591d298134ad794fd0db63a13a32bdd3a0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Aug 2023 15:04:05 +0200 Subject: [PATCH] util/StaticVector: add methods erase(), pop_front() --- src/util/StaticVector.hxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/util/StaticVector.hxx b/src/util/StaticVector.hxx index cbc13dea0..570ab0e30 100644 --- a/src/util/StaticVector.hxx +++ b/src/util/StaticVector.hxx @@ -206,10 +206,27 @@ public: return *Launder(&array[the_size++]); } + constexpr void pop_front() noexcept { + assert(!empty()); + + erase(begin()); + } + constexpr void pop_back() noexcept { assert(!empty()); back().~T(); --the_size; } + + constexpr iterator erase(iterator first, iterator last) noexcept { + std::size_t n = std::distance(first, last); + std::move(last, end(), first); + the_size -= n; + return first; + } + + constexpr iterator erase(iterator pos) noexcept { + return erase(pos, std::next(pos)); + } };