Iterators for D

Sean Kelly sean at f4.ca
Mon Nov 6 13:21:34 PST 2006


rm wrote:
> Walter Bright wrote:
>> Walter Bright wrote:
>>> .being property returns an iterator that starts at the beginning
>>
>> Make that .begin
>>
>> Also, overloading += will be used to advance the iterator.
> 
> that would give something like this?
> 
> import std.stdio;
> 
> void main()
> {
>     char[] s = "hello";
>     // += for advancing an iterator, why not ++?
>     for (iterator i = s.begin; i != s.end; i += 1)
>         writefln(s[i]);

Oh right, that's what doesn't seem to work with the C++ model--such an 
iterator wouldn't work in foreach:

     foreach( e; s.begin() ) // nowhere to supply s.end()

I think the Java style may be more appropriate:

     foreach( e; s.fwdIter() )
     foreach( e; s.revIter() )


Sean



More information about the Digitalmars-d mailing list