summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorBen Maxwell <macdue@dueutil.tech>2022-04-02 02:23:33 +0100
committerAndreas Kling <kling@serenityos.org>2022-04-02 21:50:41 +0200
commit0f2c1f804e9dbe28ce01d6e0e11090b7e6473ac0 (patch)
tree9b4294ec2d2c86879985145075a06240318bbf98 /AK
parent77add584fa8a69b262738f0b1a5697fbde306ae4 (diff)
downloadserenity-0f2c1f804e9dbe28ce01d6e0e11090b7e6473ac0.zip
AK: Add last() utility function to Span
Diffstat (limited to 'AK')
-rw-r--r--AK/Span.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/AK/Span.h b/AK/Span.h
index bd379d0e6c..972b002f15 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);