Another cool mini-project: advance a range within n steps from its end
Sebastiaan Koppe via Digitalmars-d
digitalmars-d at puremagic.com
Sat Dec 5 08:22:16 PST 2015
On Saturday, 5 December 2015 at 01:03:05 UTC, Andrei Alexandrescu
wrote:
>> What exactly doesn't work?
>
> Forward ranges.
I see; retro requires a bidirectional range.
I was thinking about
void main()
{
import std.algorithm : count;
import std.range : drop;
import std.stdio : writeln;
auto a = [1,2,3,4,5];
writeln(a.drop(a.count-3));
}
But it has the downside that it calls front/empty/pop 2*n times.
What about using a rangified circular buffer of the same size you
want the tail to be, and lazily fill it?
More information about the Digitalmars-d
mailing list