Using algorithms with ranges

mipri mipri at minimaltype.com
Thu Oct 3 09:22:32 UTC 2019


On Thursday, 3 October 2019 at 08:52:22 UTC, Andrea Fontana wrote:
> On Thursday, 3 October 2019 at 05:33:04 UTC, mipri wrote:
>> void main() {
>>     import std.range : iota;
>>
>>     foreach (x; iota(1, 10).withHistory)
>>         writeln(x);
>> }
>
>
> This doesn't work as expected, I think.
>
> auto r = iota(1,10).withHistory;
>
> writeln(r.front);
> writeln(r.front);

Oops. That output should be the same, since popFront hasn't been 
called.

The code's also bad for preserving the entire history when only 
the
latest is needed for what it's doing.


More information about the Digitalmars-d-learn mailing list