RFC: naming for FrontTransversal and Transversal ranges

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Apr 30 18:05:06 PDT 2009


bearophile wrote:
> Andrei Alexandrescu:
>> Does any of this make sense? :o)
> 
> Yes. I think problems aren't finished yet and more thinking is
> expected, but you are getting somewhere (I can tell it also because I
> am starting to understand. I am not bright.

Bright is only one :o).

> When even I understand it
> often means that the design is meaningful). Regarding the foreach on
> the items I don't know/understand the syntactic need for the [] to
> scan.

Oh, that's simple. A while ago people asked, how do I iterate a 
container (assuming the container is distinct from range). So I said, 
here's how I think:

Container!int c;
...
foreach (element; c.all)
{
    ...use element...
}

People said, that sucks! With opApply I don't need to append the .all 
thingie! So I told Walter to automatically call [] against the 
container. So people can now write:

foreach (element; c)
{
    ...use element...
}

All the container has to to is define opSlice() to return its "all" range.


Andrei



More information about the Digitalmars-d mailing list