From a2f4fb9ddbd29bd2c619622b0dfddd6dab4803b8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Aug 2023 15:02:28 +0200 Subject: [PATCH] util/StaticVector: add method pop_back() --- src/util/StaticVector.hxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util/StaticVector.hxx b/src/util/StaticVector.hxx index 9ac217e84..cbc13dea0 100644 --- a/src/util/StaticVector.hxx +++ b/src/util/StaticVector.hxx @@ -115,10 +115,8 @@ public: /* we don't need to call any destructor */ the_size = 0; } else { - while (!empty()) { - back().~T(); - --the_size; - } + while (!empty()) + pop_back(); } } @@ -207,4 +205,11 @@ public: ::new(&array[the_size]) T(std::forward(args)...); return *Launder(&array[the_size++]); } + + constexpr void pop_back() noexcept { + assert(!empty()); + + back().~T(); + --the_size; + } };