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.

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

Reply via email to