Circular Buffer

Russel Winder russel at winder.org.uk
Mon Feb 10 02:40:40 PST 2014


On Mon, 2014-02-10 at 09:16 +0000, Gary Willoughby wrote:
> 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?
> 
> import std.algorithm;
> import std.array;
> import std.range;
> import std.stdio;
> 
> void main(string[] args)
> {
> 	auto data = [1,2,3];
> 
> 	assert(data.cycle.take(5).array       == [1,2,3,1,2]);
> 	assert(data.retro.cycle.take(5).array == [3,2,1,3,2]);
> }

This is why people should be using D instead of C++! This really needs
to get onto the D website somewhere.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



More information about the Digitalmars-d-learn mailing list