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.


Reply via email to