Iterators for D
Bill Baxter
dnewsgroup at billbaxter.com
Tue Nov 7 18:34:35 PST 2006
Daniel Keep wrote:
>
> Walter Bright wrote:
>> Sean Kelly wrote:
>>> Since D has slicing, the argument for using iterators to define the
>>> boundaries of a range of randomly accessible elements seems kind of
>>> small to me. ie.
>>>
>>> sort( a.begin, a.begin + 5 ); // sort the first 5 elements
>>> or
>>> sort( a[0 .. 5] );
>>>
>>> I find the second to be cleaner to look at. But I'm undecided whether
>>> we'd lose any power or flexibility by not bothering with random access
>>> iterators.
>> Hmm, instead of 'pointers as iterators', have 'arrays as iterators'.
>> That definitely sounds like a good area to explore.
>
> Hang on; aren't we back to where we are *right now*?
Close, but right now we don't have a good way to iterate over multiple
things at once.
for(i,j; i.hasNext()&&j.hasNext(); i++,j++)
{
// do something with current values of i and j
}
Or as you say to stop iteration or a generic way to return a pointer to
a particular spot in a container.
> About the only thing this *doesn't* cover are bi-directional iterators
> (say, iterating back and forth over an infinite series).
> [intersting stuff about generators and D]
If generators can handle the above cases *AND* do it with code that
simple to create and use *AND* do all that as efficiently as for loops,
then it sounds great to me. My impression was that any sort of
opApply/coroutine thing in D was not going to be so efficient.
--bb
More information about the Digitalmars-d
mailing list