From bc36e39d073a263cd9f0535707f6055e9c9b7b69 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 28 Nov 2021 01:42:26 +0100 Subject: [PATCH] AK: Simplify `Array::back()` by checking for Size > 0 We do not want `Array::max()` to be used here at all - we know the size at compile-time, after all. --- AK/Array.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AK/Array.h b/AK/Array.h index 0393aa6d56..312f15684b 100644 --- a/AK/Array.h +++ b/AK/Array.h @@ -35,8 +35,8 @@ struct Array { [[nodiscard]] constexpr T const& front() const { return at(0); } [[nodiscard]] constexpr T& front() { return at(0); } - [[nodiscard]] constexpr T const& back() const { return at(max(1, size()) - 1); } - [[nodiscard]] constexpr T& back() { return at(max(1, size()) - 1); } + [[nodiscard]] constexpr T const& back() const requires(Size > 0) { return at(Size - 1); } + [[nodiscard]] constexpr T& back() requires(Size > 0) { return at(Size - 1); } [[nodiscard]] constexpr bool is_empty() const { return size() == 0; }