diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-10 17:49:14 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-10 17:49:14 +0200 |
commit | 7670b812333f64b8ef349797cf3e2fb26765502c (patch) | |
tree | bbfae7eca9992c0dcdf2ee237dd56f9d742d6c77 /core/variant/variant.h | |
parent | 1f0f81049fc470fe10ddb64086c94b9c595ec81f (diff) | |
parent | 64146cb7f35b57b0974b82845674d58f9f3480b6 (diff) | |
download | redot-engine-7670b812333f64b8ef349797cf3e2fb26765502c.tar.gz |
Merge pull request #86518 from AThousandShips/array_iter
[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 |