On 24.03.2012 22:19, Stewart Gordon wrote:
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?
More or less fine.
Things I'm confused by:
- One of the expansions of put is
r.front = e; r.popFront();
Strange looking this one, but it allows, for instance, to output things
to a container that defines range over it's elements.
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?
It's not truly checkpoints, but rather the whole state can copied.
I believe, in some use cases checkpoints can be much smaller then the
whole state, and we haven't got a checkpoint range yet. Could be a nice
addition if proposal is sound.
--
Dmitry Olshansky