diff --git a/AK/NonnullPtrVector.h b/AK/NonnullPtrVector.h index d78dcfab7e8..1023b915212 100644 --- a/AK/NonnullPtrVector.h +++ b/AK/NonnullPtrVector.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -33,10 +33,10 @@ public: using Base::size; - using ConstIterator = SimpleIterator; + using ConstIterator = SimpleIterator; using Iterator = SimpleIterator; using ReverseIterator = SimpleReverseIterator; - using ReverseConstIterator = SimpleReverseIterator; + using ReverseConstIterator = SimpleReverseIterator; ALWAYS_INLINE constexpr ConstIterator begin() const { return ConstIterator::begin(*this); } ALWAYS_INLINE constexpr Iterator begin() { return Iterator::begin(*this); } @@ -60,17 +60,12 @@ public: return {}; } - ALWAYS_INLINE PtrType& ptr_at(size_t index) { return Base::at(index); } - ALWAYS_INLINE PtrType const& ptr_at(size_t index) const { return Base::at(index); } + ALWAYS_INLINE PtrType& ptr_at(size_t index) const { return const_cast(Base::at(index)); } - ALWAYS_INLINE T& at(size_t index) { return *Base::at(index); } - ALWAYS_INLINE T const& at(size_t index) const { return *Base::at(index); } - ALWAYS_INLINE T& operator[](size_t index) { return at(index); } - ALWAYS_INLINE T const& operator[](size_t index) const { return at(index); } - ALWAYS_INLINE T& first() { return at(0); } - ALWAYS_INLINE T const& first() const { return at(0); } - ALWAYS_INLINE T& last() { return at(size() - 1); } - ALWAYS_INLINE T const& last() const { return at(size() - 1); } + ALWAYS_INLINE T& at(size_t index) const { return const_cast(*Base::at(index)); } + ALWAYS_INLINE T& operator[](size_t index) const { return at(index); } + ALWAYS_INLINE T& first() const { return at(0); } + ALWAYS_INLINE T& last() const { return at(size() - 1); } private: // NOTE: You can't use resize() on a NonnullFooPtrVector since making the vector