diff --git a/AK/Span.h b/AK/Span.h index 7664daf723..565e2d977e 100644 --- a/AK/Span.h +++ b/AK/Span.h @@ -99,11 +99,11 @@ public: { } - ALWAYS_INLINE constexpr const T* data() const { return this->m_values; } - ALWAYS_INLINE constexpr T* data() { return this->m_values; } + [[nodiscard]] ALWAYS_INLINE constexpr const T* data() const { return this->m_values; } + [[nodiscard]] ALWAYS_INLINE constexpr T* data() { return this->m_values; } - ALWAYS_INLINE constexpr const T* offset_pointer(size_t offset) const { return this->m_values + offset; } - ALWAYS_INLINE constexpr T* offset_pointer(size_t offset) { return this->m_values + offset; } + [[nodiscard]] ALWAYS_INLINE constexpr const T* offset_pointer(size_t offset) const { return this->m_values + offset; } + [[nodiscard]] ALWAYS_INLINE constexpr T* offset_pointer(size_t offset) { return this->m_values + offset; } using ConstIterator = SimpleIterator; using Iterator = SimpleIterator; @@ -114,9 +114,9 @@ public: constexpr ConstIterator end() const { return ConstIterator::end(*this); } constexpr Iterator end() { return Iterator::end(*this); } - ALWAYS_INLINE constexpr size_t size() const { return this->m_size; } - ALWAYS_INLINE constexpr bool is_null() const { return this->m_values == nullptr; } - ALWAYS_INLINE constexpr bool is_empty() const { return this->m_size == 0; } + [[nodiscard]] ALWAYS_INLINE constexpr size_t size() const { return this->m_size; } + [[nodiscard]] ALWAYS_INLINE constexpr bool is_null() const { return this->m_values == nullptr; } + [[nodiscard]] ALWAYS_INLINE constexpr bool is_empty() const { return this->m_size == 0; } [[nodiscard]] ALWAYS_INLINE constexpr Span slice(size_t start, size_t length) const { @@ -139,7 +139,7 @@ public: return { this->m_values, min(size(), length) }; } - ALWAYS_INLINE constexpr T* offset(size_t start) const + [[nodiscard]] ALWAYS_INLINE constexpr T* offset(size_t start) const { VERIFY(start < this->m_size); return this->m_values + start; @@ -172,7 +172,7 @@ public: return size(); } - bool constexpr contains_slow(const T& value) const + [[nodiscard]] bool constexpr contains_slow(const T& value) const { for (size_t i = 0; i < size(); ++i) { if (at(i) == value) @@ -181,7 +181,7 @@ public: return false; } - bool constexpr starts_with(Span other) const + [[nodiscard]] bool constexpr starts_with(Span other) const { if (size() < other.size()) return false; @@ -189,22 +189,24 @@ public: return TypedTransfer::compare(data(), other.data(), other.size()); } - ALWAYS_INLINE constexpr const T& at(size_t index) const - { - VERIFY(index < this->m_size); - return this->m_values[index]; - } - ALWAYS_INLINE constexpr T& at(size_t index) + [[nodiscard]] ALWAYS_INLINE constexpr const T& at(size_t index) const { VERIFY(index < this->m_size); return this->m_values[index]; } - ALWAYS_INLINE constexpr const T& operator[](size_t index) const + [[nodiscard]] ALWAYS_INLINE constexpr T& at(size_t index) + { + VERIFY(index < this->m_size); + return this->m_values[index]; + } + + [[nodiscard]] ALWAYS_INLINE constexpr const T& operator[](size_t index) const { return at(index); } - ALWAYS_INLINE constexpr T& operator[](size_t index) + + [[nodiscard]] ALWAYS_INLINE constexpr T& operator[](size_t index) { return at(index); }