Dlang Features You Would Like To Share

crimaniak via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 13 04:16:46 PDT 2017


On Thursday, 13 April 2017 at 05:51:27 UTC, Dukc wrote:
> auto use(alias F, T)(T t){return F(t);}
>
> void main()
> {   import std.stdio;
>     foreach(i; 1 .. 11)
>     {   foreach(j; 1 .. 11) write((i * j).use!(x => x*x), " ");
>         writeln;
>     }
> }
>
> This way, you can avoid writing long expressions twice with 
> UFCS.
If fact you don't need any template to do this. Try the next:

     foreach(i; 1 .. 11)
     {   foreach(j; 1 .. 11) write((x => x*x)(i * j), " ");
         writeln;
     }





More information about the Digitalmars-d mailing list