util/StaticVector: add methods erase(), pop_front()

This commit is contained in:
Max Kellermann 2023-08-14 15:04:05 +02:00 committed by Max Kellermann
parent a2f4fb9ddb
commit a58275591d
1 changed files with 17 additions and 0 deletions

View File

@ -206,10 +206,27 @@ public:
return *Launder(&array[the_size++]); return *Launder(&array[the_size++]);
} }
constexpr void pop_front() noexcept {
assert(!empty());
erase(begin());
}
constexpr void pop_back() noexcept { constexpr void pop_back() noexcept {
assert(!empty()); assert(!empty());
back().~T(); back().~T();
--the_size; --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));
}
}; };