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.
This commit is contained in:
Jelle Raaijmakers 2021-11-28 01:42:26 +01:00 committed by Andreas Kling
parent 65df30d00c
commit bc36e39d07

View file

@ -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; }