AK: Support range-for iteration over a NonnullRefPtrVector<T>.
This means you can now do this: void harmonize(NonnullRefPtrVector<Voice>& voices) { for (auto& voice : voices) { voice.sing(); // Look, no "->"! } } Pretty dang cool :^)
This commit is contained in:
parent
25a1bf0c90
commit
48108ec474
Notes:
sideshowbarker
2024-07-19 13:28:38 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/48108ec474c
1 changed files with 9 additions and 0 deletions
|
@ -20,6 +20,15 @@ public:
|
|||
}
|
||||
|
||||
using Base::size;
|
||||
|
||||
using Iterator = VectorIterator<NonnullRefPtrVector, T>;
|
||||
Iterator begin() { return Iterator(*this, 0); }
|
||||
Iterator end() { return Iterator(*this, size()); }
|
||||
|
||||
using ConstIterator = ConstVectorIterator<NonnullRefPtrVector, T>;
|
||||
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); }
|
||||
|
|
Loading…
Add table
Reference in a new issue