Circular Buffer
Rene Zwanenburg
renezwanenburg at gmail.com
Tue Feb 11 08:26:05 PST 2014
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap
wrote:
> Wow! This is GREAT stuff. My use-case is slightly more complex,
> and I'm not sure how to best apply this knowledge. The retro
> reverses the array which is problematic in itself as well as
> losing the starting index location. I have an array that I'd
> like to elegantly "rotate". Best way I can show this is by
> example of an imaginary rotate function:
>
> auto data = [1,2,3];
> assert( data.cycle.rotate(2) == [3,1,2] );
> assert( data.cycle.rotate(-2) == [2,3,1] );
>
> Perhaps what I'm doing is too complex requires me making my own
> iterator or something. In my quest of writing readable
> efficient code, I'm wondering what's the best route here.
> Thanks :)
Perhaps something like this?
http://dpaste.dzfl.pl/d4b82b0b5cba
More information about the Digitalmars-d-learn
mailing list