[Core] Add iteration support to Array

This commit is contained in:
A Thousand Ships 2023-12-24 13:44:21 +01:00
parent 1f0f81049f
commit 64146cb7f3
No known key found for this signature in database
GPG key ID: 2033189A662F8BD7
15 changed files with 251 additions and 73 deletions

View file

@ -81,6 +81,22 @@ void Array::_unref() const {
_p = nullptr;
}
Array::Iterator Array::begin() {
return Iterator(_p->array.ptrw(), _p->read_only);
}
Array::Iterator Array::end() {
return Iterator(_p->array.ptrw() + _p->array.size(), _p->read_only);
}
Array::ConstIterator Array::begin() const {
return ConstIterator(_p->array.ptr(), _p->read_only);
}
Array::ConstIterator Array::end() const {
return ConstIterator(_p->array.ptr() + _p->array.size(), _p->read_only);
}
Variant &Array::operator[](int p_idx) {
if (unlikely(_p->read_only)) {
*_p->read_only = _p->array[p_idx];