Shout out to D at cppcon, when talkign about ranges.

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 7 11:59:47 PDT 2015


On 10/07/2015 07:13 PM, Jonathan M Davis wrote:
> ...
>
> If we _were_ to look at doing something more than straight ranges, we'd
> probably look more at something like Steven's cursors than adding
> iterators, though I think that there's a decent chance that that only
> really helps with containers (it's been a while since I looked at what
> he did with cursors, and I really don't remember the details), though
> for the most part, I think that containers are the primary place where
> ranges tend to get annoying. Algorithms where they're problematic do
> exist, but they seem to be rare.
>
> - Jonathan M Davis

I think the most obvious way to generalize, such that ranges cater to 
those use cases, is to introduce a type of range that additionally 
requires the primitives:

full(); // pushFront cannot be called unless false
pushFront(); // restores one element at the front of the range

The idea is:

auto r=..., s=r.save;
assert(r.full);
r.popFront();
assert(!r.full);
r.pushFront();
assert(r.full);
assert(equal(s,r));

This is analogous to list zippers in functional languages in the same 
way that input ranges are analogous to lists.




More information about the Digitalmars-d mailing list