godotengine / godotengine/godot-cpp

Iterators over Array, Pool*Array, etc.

Open
#305 9 comments 7 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

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).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.