Iterators for D
nazo
lovesyao at gmail.com
Tue Nov 7 21:34:29 PST 2006
>interface Iterator(T) {
> bool step(); // as C# MoveNext
> T value; // getter (rvalue access)
> T value(T); // setter (lvalue access)
> int opApply(...) // support foreach style iteration
>}
I think that this is more better.
interface Iterator(T) {
bool opNext(); // as C# MoveNext.
// also support in pointer with opBack().
bool opNext(int); // speed hack
T opValue; // getter (rvalue access). also support in pointer
T opValue(T); // setter (lvalue access). also support in pointer
int opApply(...) // support foreach style iteration
}
while(iter.next)//call opNext()
writefln(*iter);//call opValue()
More information about the Digitalmars-d
mailing list