associative arrays: iteration is finally here

Leandro Lucarella llucax at gmail.com
Wed Oct 28 09:21:37 PDT 2009


Pelle Månsson, el 28 de octubre a las 15:48 me escribiste:
> Andrei Alexandrescu wrote:
> >Walter has magically converted his work on T[new] into work on
> >making associative arrays true templates defined in druntime and
> >not considered very special by the compiler.
> >
> >This is very exciting because it opens up or simplifies a number
> >of possibilities. One is that of implementing true iteration. I
> >actually managed to implement last night something that allows you
> >to do:
> >
> >int[int] aa = [ 1:1 ];
> >auto iter = aa.each;
> >writeln(iter.front.key);
> >writeln(iter.front.value);
> >
> >Two other iterations are possible: by key and by value (in those
> >cases iter.front just returns a key or a value).
> >
> >One question is, what names should these bear? I am thinking of
> >makign opSlice() a universal method of getting the "all" iterator,
> >a default that every container must implement.
> >
> >For AAs, there would be a "iterate keys" and "iterate values"
> >properties or functions. How should they be called?
> >
> >
> >Thanks,
> >
> >Andrei
> aa.each, aa.keys and aa.values seem good names?

I might be too pythonic, but aa.items sounds a little better for me ;)

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Can you stand up?
I do believe it's working, good.
That'll keep you going through the show
Come on it's time to go.



More information about the Digitalmars-d mailing list