Problem with C++ ranges also exhibited by D

Atila Neves atila.neves at gmail.com
Wed Apr 17 08:35:41 UTC 2019


On Tuesday, 16 April 2019 at 12:47:51 UTC, Dukc wrote:
> On Tuesday, 16 April 2019 at 12:07:03 UTC, Atila Neves wrote:
>> This blog post shows off some problems with the ranges v3 
>> library that is going to be included in the C++20 standard 
>> library.
>
> I belive the current design is superior, because of the ease of 
> doing this:
>
> import std.algorithm;
> import std.range;
> import std.stdio;
>
> void main() {
>     iota(1, 6)
>         .map!((n) { writeln("transform ", n); return n * 2; })
>         .cache
>         .filter!(n => n % 4 == 0)
>         .writeln;
> }
>
>
> After all, sometimes you might want front() to be lazy. With 
> the current design, you have the choice.

I have to confess my ignorance on the existence of `cache`. Huh. 
Thanks!


More information about the Digitalmars-d mailing list