From 8ea029405f9f75c6f80217abfa591ccbd322a339 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 21 Jul 2021 18:22:10 +0200 Subject: [PATCH] AK: Sprinkle [[nodiscard]] on AK::Array --- AK/Array.h | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/AK/Array.h b/AK/Array.h index 9cf075c1b5e..22964c7803f 100644 --- a/AK/Array.h +++ b/AK/Array.h @@ -13,50 +13,50 @@ namespace AK { template struct Array { - constexpr T const* data() const { return __data; } - constexpr T* data() { return __data; } + [[nodiscard]] constexpr T const* data() const { return __data; } + [[nodiscard]] constexpr T* data() { return __data; } - constexpr size_t size() const { return Size; } + [[nodiscard]] constexpr size_t size() const { return Size; } - constexpr Span span() const { return { __data, Size }; } - constexpr Span span() { return { __data, Size }; } + [[nodiscard]] constexpr Span span() const { return { __data, Size }; } + [[nodiscard]] constexpr Span span() { return { __data, Size }; } - constexpr T const& at(size_t index) const + [[nodiscard]] constexpr T const& at(size_t index) const { VERIFY(index < size()); return __data[index]; } - constexpr T& at(size_t index) + [[nodiscard]] constexpr T& at(size_t index) { VERIFY(index < size()); return __data[index]; } - constexpr T const& front() const { return at(0); } - constexpr T& front() { return at(0); } + [[nodiscard]] constexpr T const& front() const { return at(0); } + [[nodiscard]] constexpr T& front() { return at(0); } - constexpr T const& back() const { return at(max(1, size()) - 1); } - constexpr T& back() { return at(max(1, size()) - 1); } + [[nodiscard]] constexpr T const& back() const { return at(max(1, size()) - 1); } + [[nodiscard]] constexpr T& back() { return at(max(1, size()) - 1); } - constexpr bool is_empty() const { return size() == 0; } + [[nodiscard]] constexpr bool is_empty() const { return size() == 0; } - constexpr T const& operator[](size_t index) const { return at(index); } - constexpr T& operator[](size_t index) { return at(index); } + [[nodiscard]] constexpr T const& operator[](size_t index) const { return at(index); } + [[nodiscard]] constexpr T& operator[](size_t index) { return at(index); } template - constexpr bool operator==(Array const& other) const { return span() == other.span(); } + [[nodiscard]] constexpr bool operator==(Array const& other) const { return span() == other.span(); } using ConstIterator = SimpleIterator; using Iterator = SimpleIterator; - constexpr ConstIterator begin() const { return ConstIterator::begin(*this); } - constexpr Iterator begin() { return Iterator::begin(*this); } + [[nodiscard]] constexpr ConstIterator begin() const { return ConstIterator::begin(*this); } + [[nodiscard]] constexpr Iterator begin() { return Iterator::begin(*this); } - constexpr ConstIterator end() const { return ConstIterator::end(*this); } - constexpr Iterator end() { return Iterator::end(*this); } + [[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); } + [[nodiscard]] constexpr Iterator end() { return Iterator::end(*this); } - constexpr operator Span() const { return span(); } - constexpr operator Span() { return span(); } + [[nodiscard]] constexpr operator Span() const { return span(); } + [[nodiscard]] constexpr operator Span() { return span(); } constexpr size_t fill(T const& value) { @@ -66,7 +66,7 @@ struct Array { return Size; } - constexpr T max() requires(requires(T x, T y) { x < y; }) + [[nodiscard]] constexpr T max() requires(requires(T x, T y) { x < y; }) { static_assert(Size > 0, "No values to max() over"); @@ -76,7 +76,7 @@ struct Array { return value; } - constexpr T min() requires(requires(T x, T y) { x > y; }) + [[nodiscard]] constexpr T min() requires(requires(T x, T y) { x > y; }) { static_assert(Size > 0, "No values to min() over");