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

ixid via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 5 03:29:56 PDT 2016


On Tuesday, 5 April 2016 at 09:22:12 UTC, Jin wrote:
> 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);
> }

Square brackets look better than curly brackets which create a 
lot of visual noise, especially when mixed with other brackets. 
It also feels neat to treat tuples like an array of mixed types.

Can't we be more aggressive about reclaiming the comma operator 
for tuples?



More information about the Digitalmars-d mailing list