To: Ori Bernstein <ori@xxxxxxxxxxxxxx>,myrddin-dev@xxxxxxxxxxxxxx
Although I kind of like Python's way best, my favorite is the Qt-way (I think).
All iterators have two methods: a "done" method and a "next" method. The "next" method returns the next value, and the "done" method says whether or not the iterator is exhausted. Calling "next" on an empty iterator is undefined.
There's also the half-STL-half-Qt way: same thing as described above, but with the C++ STL-style iterator types, the ability for a finished iterator (that is bidirectional) to go backwards, and an "end" function that returns a finished iterator. That would be a very, very powerful combo, but it would be a tad more complex than the Qt-way.
C++'s iterator types are very useful in a statically-typed context, regardless of the inclusion of other STL-ish features.
Having something like Python's generators along with this would be neat, too.
Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote:
>So, I'm looking at how I want to handle custom iteration in for loops.
>are a bunch of approaches out in the wild, and I'm trying to figure out
>how I want
>to have it done.
>Python has generators (https://www.python.org/dev/peps/pep-0255/)
>C++ has iterators
>D has ranges (http://www.informit.com/articles/printerfriendly/1407357)
>Common Lisp has the iterate module/macro/whatever
>So, it's time for a gedanken experiment. What should iterating over
>things look like, in
>an ideal world with unicorns?
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Check out my website: http://kirbyfan64.github.io/