Iterator straw-man

Bill Baxter wbaxter at gmail.com
Wed Nov 8 13:31:16 PST 2006


Benji Smith wrote:
> Bill Baxter wrote:
> 
>> I'm guessing the specially-ordained iterator method names will 
>> probably end up being opIter and opIterReverse (or maybe same with 
>> 'Iterator' spelled out) just following the pattern established so far.
> 
> 
> Why the continued assumption that there are only two valid kinds of 
> iterator? 

Because those two will be recognized specially by foreach and 
foreach_reverse without having to specify a method name.  But you'll 
still be able to pass in a specific iterator of whatever kind you wish.

A hashtable might have forward and reverse iterators for both
> its keys and its values, thereby requiring four distinct iterators. 

Yep, for hashtable you may have to name them all explicitly:
    foreach(k; ht.keys)
    foreach(v; ht.values)
    foreach(k; ht.keysReverse)
    foreach(v; ht.valuesReverse)

A
> tree might have depth-first, breadth-first, in-order, and reverse-order 
> iterators. Any collection class might have a random-order iterator. I 
> think it's awfully presumptuous to bake the notion of forward and 
> reverse iteration directly into the language.

Can't say I disagree with you, but it's already there with foreach and 
foreach_reverse and opApply/opApplyReverse.

--bb



More information about the Digitalmars-d mailing list