Proposal: Hide the int in opApply from the user

Dan murpsoft at hotmail.com
Wed Jan 9 17:41:53 PST 2008


Bill Baxter Wrote:

> bearophile wrote:
> > Paul Findlay Wrote:
> >> This is an old (1993), but I hope related, discussion:
> >> Iterators: Signs of Weakness in Object-Oriented Languages
> >> http://home.pipeline.com/~hbaker1/Iterator.html
> > 
> > Thank you for the link, it's quite interesting.
> > From that article:
> > 
> >> The problem is that the "state" of the iterator must be stored somewhere, and the only two places are in the instance of the collection or the class of the collection. 
> > 
> > If you put a D opApply as a metod of a collection class, it allows you to enumerate the Cartesian product of a collection with itself too.
> 
> In other words, the author seems to have overlooked the other place 
> where state can be stored: on the stack.
> 
> --bb

Or the other place; in registers.

Typically when you go through a loop, you generate this (on x86):

    mov ecx, length;
top:
    bla bla bla
    dec ecx;
    jnz top;

This is considerably more efficient for storing iterator state than any other means.



More information about the Digitalmars-d mailing list