uniform initialization in D (as in C++11): i{...}
Meta via Digitalmars-d
digitalmars-d at puremagic.com
Tue Apr 5 05:53:16 PDT 2016
On Tuesday, 5 April 2016 at 11:35:35 UTC, Jacob Carlborg wrote:
> On 2016-04-05 09:47, ZombineDev wrote:
>
>> D currently supports
>> Point3 p = { x:1, y:2, z:3 };
>>
>> It just needs to be extended to work in more places.
>>
>> https://issues.dlang.org/show_bug.cgi?id=15692
>
> That's only for structs. A uniform initialization syntax needs
> to be ... uniform. It has to work for everything.
D already has `typeof(return)`.
struct A{
int a;
int b;
}
A fun(A a, int b) {
if(b==1) return typeof(return)(0,1);
else if(b==2) return typeof(return)(2,3);
else return fun(typeof(return)(3,4), 1);
}
Or to better mimic the proposed syntax:
A fun(A a, int b) {
alias i = typeof(return);
if(b==1) return i(0,1);
else if(b==2) return i(2,3);
else return fun(i(3,4), 1);
}
More information about the Digitalmars-d
mailing list