When does take modify the underlying iterator?

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 16 14:41:00 PDT 2016


On 08/16/2016 11:34 PM, ag0aep6g wrote:
> As for the example, you can rewrite it like so:
>
> ----
> auto failhard(T)(T iter) {
>     import std.stdio;
>     import std.range: take, drop, refRange;
>
>     writeln("We have some range:");
>     writeln(typeid(T));
>     writeln("We take 1 from it...");
>     writeln(refRange(&iter).take(1));
>     writeln("The rest of the range has:");
>     writeln(iter);
>     writeln("");
> }
> ----
>
> Also need to add @property to `front` and `empty` in the ranges.
> refRange is picky about this.

My apologies, that actually prints "[0, 1, 2, 3]" in the array case. I 
don't what's going on. That should work. Maybe I'm misunderstanding 
something about refRange.


More information about the Digitalmars-d-learn mailing list