RFC on range design for D2
Don
nospam at nospam.com.au
Wed Sep 10 00:52:24 PDT 2008
Andrei Alexandrescu wrote:
> In most slice-based D programming, using bare pointers is not necessary.
> Could then there be a way to use _only_ ranges and eliminate iterators
> altogether? A container/range design would be much simpler than one also
> exposing iterators.
> http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.html
I like this a lot. You've mentioned safety and simplicity, but it also
seems to be a more powerful abstraction than STL-style iterators.
Consider a depth-first-search over a tree. You have a start point, an
end point, and some internal state (in this case, some kind of stack).
The interesting thing is that the required internal state _may depend on
the values of the start & end points_.
STL iterators don't model this very well, since they require a symmetry
between iterators. Which creates the difficulty of where the internal
state should be stored.
You can get away with independent iterators when the relationship
between start and end is, "if you perform ++ on start enough times, you
reach end". A simple array-style range formalizes this relationship, but
the range concept also allows more complex relationships to be expressed.
So I think the value of this approach improves for more complicated
iterators than the simple ones used by the STL.
More information about the Digitalmars-d-announce
mailing list