Get n-th

Jonathan M Davis jmdavisProg at gmx.com
Wed Feb 23 04:50:01 PST 2011


On Wednesday 23 February 2011 04:34:28 bearophile wrote:
> Jonathan M Davis:
> > Assuming that it's a forward range rather than an input range:
> > 
> > auto s = range.save;
> > s.popFrontN(n - 1);
> > writeln(s.front);
> 
> This program gives:
> test.d(5): Error: no property 'popFrontN' for type
> 'Recurrence!(fun,int,2u)'
> 
> import std.stdio, std.array, std.range;
> void main() {
>     auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1);
>     auto s = fib.save;
>     s.popFrontN(10 - 1);
>     writeln(s.front);
> }
> 
> Thank you,
> bye,
> bearophile

Okay, so you need to do popFrontN(s, n - 1). I'm too used to arrays which allow 
you to use that sort of syntax. That and not bothering with [] when slicing seem 
to be the two biggest problems that I'm seeing when dealing with ranges which 
aren't arrays. I'm just too used to arrays.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list