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/variant.h | |
parent | 1f0f81049fc470fe10ddb64086c94b9c595ec81f (diff) | |
download | redot-engine-64146cb7f35b57b0974b82845674d58f9f3480b6.tar.gz |
[Core] Add iteration support to `Array`
Diffstat (limited to 'core/variant/variant.h')
-rw-r--r-- | core/variant/variant.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/core/variant/variant.h b/core/variant/variant.h index fc4030ac5a..10f8dc3c7f 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -865,4 +865,56 @@ Callable Callable::bind(VarArgs... p_args) const { return bindp(sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args)); } +Variant &Array::Iterator::operator*() const { + if (unlikely(read_only)) { + *read_only = *element_ptr; + return *read_only; + } + return *element_ptr; +} + +Variant *Array::Iterator::operator->() const { + if (unlikely(read_only)) { + *read_only = *element_ptr; + return read_only; + } + return element_ptr; +} + +Array::Iterator &Array::Iterator::operator++() { + element_ptr++; + return *this; +} + +Array::Iterator &Array::Iterator::operator--() { + element_ptr--; + return *this; +} + +const Variant &Array::ConstIterator::operator*() const { + if (unlikely(read_only)) { + *read_only = *element_ptr; + return *read_only; + } + return *element_ptr; +} + +const Variant *Array::ConstIterator::operator->() const { + if (unlikely(read_only)) { + *read_only = *element_ptr; + return read_only; + } + return element_ptr; +} + +Array::ConstIterator &Array::ConstIterator::operator++() { + element_ptr++; + return *this; +} + +Array::ConstIterator &Array::ConstIterator::operator--() { + element_ptr--; + return *this; +} + #endif // VARIANT_H |