Making sense of ranges
Stewart Gordon
smjg_1998 at yahoo.com
Sat Mar 24 11:19:32 PDT 2012
The documentation for std.range states
http://dlang.org/phobos/std_range.html
"This module defines the notion of range (by the membership tests isInputRange,
isForwardRange, isBidirectionalRange, isRandomAccessRange), range capability tests (such
as hasLength or hasSlicing), and a few useful range incarnations."
But that intro doesn't describe what a range actually is.
Here's what I've made out so far:
- Ranges are basically a generalised API for accessing a container or stream that is
linear in logical structure and can have any element type.
- What is a range and what isn't is determined by compile-time duck typing - testing
whether it implements certain methods.
- A range over a finite data structure is essentially equivalent to a start/end iterator
pair as used by various C++ STL functions.
- Where a function in std.range is described as iterating through ranges in a particular
way, what this function does is to return a range that delivers the resulting sequence.
Have I got all this right?
Things I'm confused by:
- One of the expansions of put is
r.front = e; r.popFront();
What has putting something at the front of a range and then popping it to do with
outputting to the range?
- Why is a range that can save checkpoints called a "forward" range?
Stewart.
More information about the Digitalmars-d-learn
mailing list