Ranges and/versus iterators

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Mar 23 13:46:28 PDT 2010


On 03/23/2010 06:58 AM, clueless bystander wrote:
> Lars T. Kyllingstad Wrote:
>
>> clueless bystander wrote:
>>> Watching D evolve from the outside there seems to be a lot of ongoing discussion
>>> on this newsgroup about the D range idiom which is somehow opposed to conventional
>>> thinking about iterators.
>>>
>>> Can someone please explain in plain words just exactly what a range is and how
>>> it differs from the iterator concept (if that's appropriate???) and what are the benefits
>>> from a data modeling and access perspective.
>>>
>>> Sure, I'm clueless, though suspect many other bystanders would appreciate a
>>> succinct heads-up.
>>>
>>> Thanks,
>>> clueless bystander
>>
>>
>> I'm probably not the right person to answer your question, since I have
>> virtually no experience with C++ iterators.  Instead I'll just refer you
>> to Andrei's own article on the subject:
>>
>>     http://www.informit.com/articles/article.aspx?p=1407357
>>
>> Please don't hesitate to ask again if it didn't clear things up for you. :)
>>
>> -Lars
>
> Yes, well, thanks again.  The first 7 pages seemed to have plausible arguments
> but the going get tough thereafter.  Maybe the reason ranges are not popular
> is that they are hard to explain even though they might be simple and obvious
> in hindsight.
>
> Sigh,
> c.b.

Thank you for your interest. The article 
(http://erdani.com/publications/on-iteration.html) is long because 
following my keynote talk at BoostCon 2009, I've received a flurry of 
emails asking me to flesh out the ranges design in greater detail and to 
better motivate them. That article not only describes the design, but it 
also explains the historical artifacts that led to today's imperfect 
state of affairs, motivates defining ranges with categories, and gives 
examples.

The price for such thoroughness is - sorry - size.

If you are familiar with STL iterators and GoF-style iterators (with 
hasmore/get/advance), ranges are so simple, they define themselves: a 
range is a GoF-style iterator that recognizes the necessity of STL's 
iterator categories (input, forward, bidirectional, and random). All the 
rest is aftermath.


Andrei



More information about the Digitalmars-d mailing list