From 0f2c1f804e9dbe28ce01d6e0e11090b7e6473ac0 Mon Sep 17 00:00:00 2001 From: Ben Maxwell Date: Sat, 2 Apr 2022 02:23:33 +0100 Subject: [PATCH] AK: Add last() utility function to Span --- AK/Span.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/AK/Span.h b/AK/Span.h index bd379d0e6cd..972b002f159 100644 --- a/AK/Span.h +++ b/AK/Span.h @@ -212,6 +212,16 @@ public: return this->m_values[index]; } + [[nodiscard]] ALWAYS_INLINE constexpr T const& last() const + { + return this->at(this->size() - 1); + } + + [[nodiscard]] ALWAYS_INLINE constexpr T& last() + { + return this->at(this->size() - 1); + } + [[nodiscard]] ALWAYS_INLINE constexpr T const& operator[](size_t index) const { return at(index);