godot-cpp
godot-cpp copied to clipboard
Iterators over Array, Pool*Array, etc.
In GDScript you can do the following to iterate over an array:
things = [1,2,3,4,5]
for x in things:
# do something with x
pass
C++11 added support for for-each loops that look like
for (Thing& x : container)
; // do thing with x
but it requires the class of container to define the members begin() and end(), which return iterators to the first element and to after the last element of the container.
I think iterators types should be defined for Array and Pool*Array, as well as begin and end members. The one for array could be represented with a pointer to the Array and an index, while the ones for the pool arrays could just be a pointer (like how std::vector is typically implemented).