From 48108ec474ce0efa690ad6257b39c3737aa039da Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 27 Jun 2019 12:11:58 +0200 Subject: [PATCH] AK: Support range-for iteration over a NonnullRefPtrVector. This means you can now do this: void harmonize(NonnullRefPtrVector& voices) { for (auto& voice : voices) { voice.sing(); // Look, no "->"! } } Pretty dang cool :^) --- AK/NonnullRefPtrVector.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AK/NonnullRefPtrVector.h b/AK/NonnullRefPtrVector.h index a87a6086149..b2963910152 100644 --- a/AK/NonnullRefPtrVector.h +++ b/AK/NonnullRefPtrVector.h @@ -20,6 +20,15 @@ public: } using Base::size; + + using Iterator = VectorIterator; + Iterator begin() { return Iterator(*this, 0); } + Iterator end() { return Iterator(*this, size()); } + + using ConstIterator = ConstVectorIterator; + ConstIterator begin() const { return ConstIterator(*this, 0); } + ConstIterator end() const { return ConstIterator(*this, size()); } + T& at(int index) { return *Base::at(index); } const T& at(int index) const { return *Base::at(index); } T& operator[](int index) { return at(index); }