summaryrefslogtreecommitdiffstats
path: root/core/variant/array.cpp
diff options
context:
space:
mode:
authorA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2023-12-24 13:44:21 +0100
committerA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-04-10 14:49:34 +0200
commit64146cb7f35b57b0974b82845674d58f9f3480b6 (patch)
treebbfae7eca9992c0dcdf2ee237dd56f9d742d6c77 /core/variant/array.cpp
parent1f0f81049fc470fe10ddb64086c94b9c595ec81f (diff)
downloadredot-engine-64146cb7f35b57b0974b82845674d58f9f3480b6.tar.gz
[Core] Add iteration support to `Array`
Diffstat (limited to 'core/variant/array.cpp')
-rw-r--r--core/variant/array.cpp16
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];