summaryrefslogtreecommitdiff
path: root/AK/Span.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-19 18:13:36 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-19 18:29:13 +0100
commit050eb5afa88c75a053b78b484b761344fc91ecff (patch)
treed6124684384d4bde76bc79b9cd4674afc4e75d6c /AK/Span.h
parenta8dbfc3398e685083d39e7cfdb43cc612d6df7fb (diff)
downloadserenity-050eb5afa88c75a053b78b484b761344fc91ecff.zip
AK: Mark some Span functions with [[nodiscard]]
I was confused by the trim() API, thinking it would mutate the span it was called on. Mark all const functions that return a new span with [[nodiscard]] so we can catch such mistakes.
Diffstat (limited to 'AK/Span.h')
-rw-r--r--AK/Span.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/AK/Span.h b/AK/Span.h
index e3c9a3eefe..7bfae70adf 100644
--- a/AK/Span.h
+++ b/AK/Span.h
@@ -134,18 +134,18 @@ public:
ALWAYS_INLINE constexpr bool is_null() const { return this->m_values == nullptr; }
ALWAYS_INLINE constexpr bool is_empty() const { return this->m_size == 0; }
- ALWAYS_INLINE constexpr Span slice(size_t start, size_t length) const
+ [[nodiscard]] ALWAYS_INLINE constexpr Span slice(size_t start, size_t length) const
{
ASSERT(start + length <= size());
return { this->m_values + start, length };
}
- ALWAYS_INLINE constexpr Span slice(size_t start) const
+ [[nodiscard]] ALWAYS_INLINE constexpr Span slice(size_t start) const
{
ASSERT(start <= size());
return { this->m_values + start, size() - start };
}
- ALWAYS_INLINE constexpr Span trim(size_t length) const
+ [[nodiscard]] ALWAYS_INLINE constexpr Span trim(size_t length) const
{
return { this->m_values, min(size(), length) };
}