foreach vs. iterators
Bill Baxter
wbaxter at gmail.com
Sun Nov 5 12:04:40 PST 2006
Sean Kelly wrote:
> Bill Baxter wrote:
>
>> 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()) )
>> {
>> }
>
>
> Yup, but this seems confusing with the presence of val() methods.
I'm not sold on val() yet. :-)
--bb
More information about the Digitalmars-d-announce
mailing list