Modern C++ Lamentations

John Colvin john.loughran.colvin at gmail.com
Sun Dec 30 12:22:01 UTC 2018


On Saturday, 29 December 2018 at 22:01:58 UTC, Steven 
Schveighoffer wrote:
> On 12/29/18 4:29 AM, Walter Bright wrote:
>> http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
>> 
>> Time to show off your leet D skilz and see how good we can do 
>> it in D!
>
> Ugh, ranges really aren't a good fit for emulating nested 
> loops, unless you write a specialized one.
>
> I tried my best, but it kind of sucks:
>
>     foreach(z, x, y;
>     iota(size_t.max)
>         .map!(a =>
>              zip(StoppingPolicy.shortest, a.repeat, iota(1, a)))
>         .joiner
>         .map!(t =>
>              zip(StoppingPolicy.shortest, t[0].repeat, 
> t[1].repeat, iota(t[1], t[0])))
>         .joiner
>         .filter!(t => t[0]*t[0] == t[1]*t[1] + t[2]*t[2])
>         .take(100))
>     {
>         writeln(x, " ", y, " ", z);
>     }

Or if you can bear the closures

     iota(1, size_t.max)
         .map!(z => iota(1, z + 1)
               .map!(x => iota(x, z + 1)
                     .map!(y => tuple!("x", "y", "z")(x, y, z)))
               .joiner)
         .joiner
         .filter!(t => t.x^^2 + t.y^^2 == t.z^^2);




More information about the Digitalmars-d mailing list