diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index b89799abcfc8..ee3e54540ee6 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -57,6 +57,16 @@ class LocalVector { return data; } + T &back() { + CRASH_BAD_UNSIGNED_INDEX(0, count); + return data[count - 1]; + } + + const T &back() const { + CRASH_BAD_UNSIGNED_INDEX(0, count); + return data[count - 1]; + } + // Must take a copy instead of a reference (see GH-31736). _FORCE_INLINE_ void push_back(T p_elem) { if (unlikely(count == capacity)) { @@ -72,6 +82,14 @@ class LocalVector { } } + void pop_back() { + ERR_FAIL_COND(count == 0); + count--; + if constexpr (!std::is_trivially_destructible_v && !force_trivial) { + data[count].~T(); + } + } + void remove_at(U p_index) { ERR_FAIL_UNSIGNED_INDEX(p_index, count); count--;