To keep this reply brief, I'll just summarize:
Lots of great takeaways from both of your posts, and a handful of
topics you mentioned that I need to dig into further now. This is
great (I too like D :)
I very much appreciate the extra insight into how things work and
why certain design
On 6/28/20 9:07 AM, Denis wrote:
> * foreach is the actual iterator,
Yes. foreach is "lowered" to the following equivalent:
for ( ; !range.empty; range.popFront()) {
// Use range.front here
}
A struct can support foreach iteration through its opCall() member
function as well.
Many thanks: your post has helped me get past the initial
stumbling blocks I was struggling with. I do have a followup
question.
First, here are my conclusions up to this point, based on your
post above, some additional experimentation, and further research
(for future reference, and for any
On 6/27/20 8:19 PM, Denis wrote:
> Is it possible to write an iterator
It is arguable whether D's ranges are iterators but if nouns are useful,
we call them ranges. :) (Iterators can be written in D as well and then
it would really be confusing.)
>struct letters {
> string str;
>
Is it possible to write an iterator that does the following,
using a struct and some functions?
- Operates in a foreach loop
- Has BEGIN-like and END-like blocks or functions that are
executed automatically, before and after the iterations
- Initializes variables in the BEGIN block that are