Are iterators and ranges going to co-exist?
Jim Balter
Jim at Balter.name
Sat Jul 24 06:01:14 PDT 2010
"Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message
news:op.vf5kynqgeav7ka at localhost.localdomain...
> On Tue, 20 Jul 2010 09:52:00 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> On 07/20/2010 03:01 AM, Peter Alexander wrote:
>>> Some more arguments for iterators/cursors:
>>>
>>> 1. How would you implement Floyd's cycle finding algorithm using ranges?
>>> (http://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare)
>>> It uses two iterators over the same range. You would have to wastefully
>>> use 2 ranges that have the same end coordinate.
>>
>> I think there's a confusion somewhere. You may want to check out the
>> SList definition in std.algorithm. A SList range is exactly one pointer
>> thick. With singly-linked lists it's the iterator approach that is
>> wasteful because it canonically transports a null pointer as end().
>
> That is an example of a single exception to the rule :) AFAIK, no other
> container types have ranges with no end pointer or length.
zstrings, pipes, and various other streams. Various calculated numeric
series. Ropes and other binary trees (threaded trees can be traversed with a
single pointer and no stack). Probably other classses of containers. And
while SLists are "so (sic) unique", very large amounts of very sophisticated
code have been written using just that "limited" datatype.
> It also makes SList ranges less expressive. For example, what if I wanted
> a range between two elements in the list? Such a range is actually
> unconstructable. SList is not a very good example of a container, because
> it is so unique and limited.
>
> -Steve
More information about the Digitalmars-d
mailing list