On Sat, 24 Jul 2010 09:01:14 -0400, Jim Balter <j...@balter.name> wrote:


"Steven Schveighoffer" <schvei...@yahoo.com> wrote in message news:op.vf5kynqgeav...@localhost.localdomain...
On Tue, 20 Jul 2010 09:52:00 -0400, Andrei Alexandrescu <seewebsiteforem...@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.

Streams are in a completely different category.  They are not containers.

I personally feel that imposing the range/iterator/cursor idiom on top of a stream is a problematic model that's only done "because you can." Kind of like the one-liner qsort in a functional language.

Various calculated numeric series.

Those don't have ends afaik, and are read-only. Take works perfectly fine in those cases where you need "n elements", in which case you have an end point ;)

Ropes and other binary trees (threaded trees can be traversed with a single pointer and no stack).

I'm not familiar with the internal structure of Ropes.

Look, technically, any node-based container can have a single-pointer range, but it leaves you with only one type of range -- one that goes to the end. That doesn't sound very useful to me.

Probably other classses of containers. And while SLists are "so (sic) unique",

I meant 'so'

very large amounts of very sophisticated code have been written using just that "limited" datatype.

No, SList is brand new, not much code has been written with it ;) You may object, but try using it and see how far it takes you. SList is like a normal singly linked-list but with all the power removed for safety reasons.

-Steve

Reply via email to