Circular Buffer

monarch_dodra monarchdodra at gmail.com
Thu Feb 13 09:49:27 PST 2014


On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap 
wrote:
> (disclaimer: I'm new around here)
> Is it possible to cycle backwards? If not, what's the best 
> approach?
>
> Example of some ideal "takeBack" function:
> data = cycle([1,2,3][])
> take(data, 4) is [1,2,3,1][]
> takeBack(data, 4) would be [1,3,2,1][]
>
> Thoughts?

We've had a discussion about this recently with Andrej Mitrovic.

The question was basically: Should Cycle (keeping in mind it is 
an infinite range) be bidirectional? And if yes, what should be 
the first last?

There is fundamentally nothing preventing us from making Cycle 
bidirection (though maybe as opt-in CycleBidirectional, due to 
extra costs). We'd just need a use case, and specifications I 
guess. For example:

auto s = cycle([1, 2, 3]);
auto last = cycle.back;

What's last's value? I think it should be 3. If we can agree and 
file an ER, it can be done.


More information about the Digitalmars-d-learn mailing list