Iterators recap
Sean Kelly
sean at f4.ca
Fri Dec 15 02:01:24 PST 2006
Bill Baxter wrote:
> Sean Kelly wrote:
>> Bill Baxter wrote:
>>> Sean Kelly wrote:
>>>> Bill Baxter wrote:
>>>>>
>>>>> Too bad the iterator discussions fizzled out without anything
>>>>> getting decided.
>>>>
>>>> I think the design was pretty well settled when things ended. The
>>>> next step would be a sample implementation so folks could wrangle
>>>> over syntax. It's on my "to do" list, but I'm a bit short on free
>>>> time at the moment.
>>>
>>> Huh. So what is your understanding of what the consensus was?
>>
>> Java-style, with random access iterators overloading array operations.
>> I can't remember if there was any clear preference for the
>> hasNext/getNext vs. the atEnd/getVal approach, but I tend to favor the
>> latter.
>
> I like next/value/(ptr) myself.
> Makes for very succinct while loops. ptr available where it makes sense.
>
> while(iter.next()) { writefln(iter.value); }
>
> while(iter.next()) { *iter.ptr = 17; }
It's great for loops, but can be confusing when iterators stick around
for a while. Say I have some code that operates on the current value of
an iterator. With the next() approach, how do I know whether the
iterator is valid? Still, perhaps a hybrid approach is best. Have next
return true on success and offer an atEnd property as well.
Sean
More information about the Digitalmars-d-learn
mailing list