From e29fb75321bafb93474112d98fc95d9e379acca7 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Thu, 21 Aug 2025 08:19:03 -0400 Subject: [PATCH] Add ConstIterator conversions for missing container Iterators --- binding_generator.py | 10 ++++++++++ include/godot_cpp/templates/local_vector.hpp | 5 +++++ include/godot_cpp/templates/rb_map.hpp | 5 +++++ include/godot_cpp/templates/rb_set.hpp | 5 +++++ include/godot_cpp/templates/vector.hpp | 5 +++++ 5 files changed, 30 insertions(+) diff --git a/binding_generator.py b/binding_generator.py index d5ffc1456..94977c7f8 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -832,6 +832,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append(f"\tconst {return_type} *ptr() const;") result.append(f"\t{return_type} *ptrw();") iterators = """ + struct ConstIterator; struct Iterator { _FORCE_INLINE_ $TYPE &operator*() const { return *elem_ptr; @@ -853,6 +854,10 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl Iterator() {} Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; } + operator ConstIterator() const { + return ConstIterator(elem_ptr); + } + private: $TYPE *elem_ptr = nullptr; }; @@ -912,6 +917,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append("\tVariant &operator[](int64_t p_index);") result.append("\tvoid set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);") result.append(""" + struct ConstIterator; struct Iterator { _FORCE_INLINE_ Variant &operator*() const; _FORCE_INLINE_ Variant *operator->() const; @@ -925,6 +931,10 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl Iterator() {} Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; } + operator ConstIterator() const { + return ConstIterator(elem_ptr); + } + private: Variant *elem_ptr = nullptr; }; diff --git a/include/godot_cpp/templates/local_vector.hpp b/include/godot_cpp/templates/local_vector.hpp index 0ef322fba..936d44a4d 100644 --- a/include/godot_cpp/templates/local_vector.hpp +++ b/include/godot_cpp/templates/local_vector.hpp @@ -180,6 +180,7 @@ class LocalVector { return data[p_index]; } + struct ConstIterator; struct Iterator { _FORCE_INLINE_ T &operator*() const { return *elem_ptr; @@ -201,6 +202,10 @@ class LocalVector { Iterator() {} Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; } + operator ConstIterator() const { + return ConstIterator(elem_ptr); + } + private: T *elem_ptr = nullptr; }; diff --git a/include/godot_cpp/templates/rb_map.hpp b/include/godot_cpp/templates/rb_map.hpp index c0dc4bf33..71a8dd12e 100644 --- a/include/godot_cpp/templates/rb_map.hpp +++ b/include/godot_cpp/templates/rb_map.hpp @@ -98,6 +98,7 @@ class RBMap { typedef KeyValue ValueType; + struct ConstIterator; struct Iterator { friend class RBMap; @@ -128,6 +129,10 @@ class RBMap { Iterator() {} Iterator(const Iterator &p_it) { E = p_it.E; } + operator ConstIterator() const { + return ConstIterator(E); + } + private: Element *E = nullptr; }; diff --git a/include/godot_cpp/templates/rb_set.hpp b/include/godot_cpp/templates/rb_set.hpp index 612be9115..7187c0f81 100644 --- a/include/godot_cpp/templates/rb_set.hpp +++ b/include/godot_cpp/templates/rb_set.hpp @@ -84,6 +84,7 @@ class RBSet { typedef T ValueType; + struct ConstIterator; struct Iterator { _FORCE_INLINE_ T &operator*() const { return E->get(); @@ -106,6 +107,10 @@ class RBSet { Iterator() {} Iterator(const Iterator &p_it) { E = p_it.E; } + operator ConstIterator() const { + return ConstIterator(E); + } + private: Element *E = nullptr; }; diff --git a/include/godot_cpp/templates/vector.hpp b/include/godot_cpp/templates/vector.hpp index 51eb825d3..7c1f5dd28 100644 --- a/include/godot_cpp/templates/vector.hpp +++ b/include/godot_cpp/templates/vector.hpp @@ -218,6 +218,7 @@ class Vector { return false; } + struct ConstIterator; struct Iterator { _FORCE_INLINE_ T &operator*() const { return *elem_ptr; @@ -239,6 +240,10 @@ class Vector { Iterator() {} Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; } + operator ConstIterator() const { + return ConstIterator(elem_ptr); + } + private: T *elem_ptr = nullptr; };