uniform initialization in D (as in C++11): i{...}

Jin via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 5 02:22:12 PDT 2016


On Tuesday, 5 April 2016 at 05:39:25 UTC, Timothee Cour wrote:
> what's D's answer for C++11's uniform initialization [1] which 
> allows DRY code?
>
> Could we have this:
> ----
> struct A{
>   int a;
>   int b;
> }
>
> A fun(A a, int b) {
>   if(b==1) return i{0,1};
>   else if(b==2) return i{2,3};
>   else return fun(i{3,4}, 1);
> }
> ----

A fun(A a, int b) {
   if(b==1) return [0,1];
   else if(b==2) return [a:2,b:3];
   else return fun([3,4], 1);
}



More information about the Digitalmars-d mailing list