diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2023-12-24 13:44:21 +0100 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-04-10 14:49:34 +0200 |
commit | 64146cb7f35b57b0974b82845674d58f9f3480b6 (patch) | |
tree | bbfae7eca9992c0dcdf2ee237dd56f9d742d6c77 /core/variant/array.cpp | |
parent | 1f0f81049fc470fe10ddb64086c94b9c595ec81f (diff) | |
download | redot-engine-64146cb7f35b57b0974b82845674d58f9f3480b6.tar.gz |
[Core] Add iteration support to `Array`
Diffstat (limited to 'core/variant/array.cpp')
-rw-r--r-- | core/variant/array.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 5d6fbb8bed..3685515db5 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -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]; |