foreach vs. iterators
Bill Baxter
wbaxter at gmail.com
Sun Nov 5 10:01:45 PST 2006
Sean Kelly wrote:
> Sean Kelly wrote:
>
>> Still, I think it's useful to have in an iterator, so perhaps
>> something roughly like this:
>>
>> interface Iterator(T)
>> {
>> T val();
>> T next();
>> bool hasNext();
>> }
>
>
> Err... this doesn't work for an iterator returned for an empty
> container.
It's fine if you define the behavior to be that you have to call next()
once to get the first value. So for iteration idiom becomes:
T v;
while(c.hasNext()) )
{
}
More information about the Digitalmars-d-announce
mailing list