Thread overview
D Uniform initialization {}
Oct 21, 2016
Patric Dexheimer
Oct 21, 2016
Daniel Kozak
Oct 21, 2016
Patric Dexheimer
Oct 21, 2016
Daniel Kozak
Oct 22, 2016
Patric Dexheimer
Oct 23, 2016
Seb
Oct 23, 2016
mogu
October 21, 2016
Quite sure that this was already discussed, but.. any chance of this on D?
(one of the few things that i miss from c++)

There are a lot of places where it should make the code clear.
I always have to create shorter aliases for the most used structs. (which i think is awkward sometimes)

I know there is the case of being ambiguous with lambdas, but after reading this thread https://forum.dlang.org/thread/nud21i$o29$1@digitalmars.com
uniform initialization comes to my mind again :)







October 21, 2016
Dne 21.10.2016 v 20:49 Patric Dexheimer via Digitalmars-d napsal(a):

> Quite sure that this was already discussed, but.. any chance of this on D?
No (I hope so)
>
> There are a lot of places where it should make the code clear.
Can you elaborate on this?
> I always have to create shorter aliases for the most used structs. (which i think is awkward sometimes)
Why? (I do not see any relation to Uniform initialization)

October 21, 2016
On Friday, 21 October 2016 at 19:20:25 UTC, Daniel Kozak wrote:
> Dne 21.10.2016 v 20:49 Patric Dexheimer via Digitalmars-d napsal(a):
>
>> Quite sure that this was already discussed, but.. any chance of this on D?
> No (I hope so)
>>
>> There are a lot of places where it should make the code clear.
> Can you elaborate on this?
>> I always have to create shorter aliases for the most used structs. (which i think is awkward sometimes)
> Why? (I do not see any relation to Uniform initialization)

egs:
//D
alias vec3 = Tuple!(float, "x", float, "y", float, "z");
vec3[] vectors = [
   vec3(1.0,0.0,1.0),
   vec3(2.0,1.0,1.0),
   vec3(3.0,2.0,1.0)
];
//C++ equivalent
vec3 vectors[] = {
   {1.0,0.0,1.0},
   {2.0,1.0,1.0},
   {3.0,2.0,1.0}
};

//D
auto return_value = get_struct(); //don´t need to write the return type
set_struct( StructName(value1, value2) );
//C++
set_struct( {value1, value2} ); //don´t need to write the argument type

//D in case of large struct names
alias v = VeryLargeStructName; //not cool
v[] vectors = [
   v(1.0,0.0,1.0),
   v(2.0,1.0,1.0),
   v(3.0,2.0,1.0)
];


I find myself falling with frequency on examples that will benefit from the c++ uniform initialization.

"No (I hope so)"

Can you explain why you think is a bad idea?
October 21, 2016
Dne 21.10.2016 v 23:21 Patric Dexheimer via Digitalmars-d napsal(a):

> On Friday, 21 October 2016 at 19:20:25 UTC, Daniel Kozak wrote:
>> Dne 21.10.2016 v 20:49 Patric Dexheimer via Digitalmars-d napsal(a):
>>
>>> Quite sure that this was already discussed, but.. any chance of this on D?
>> No (I hope so)
>>>
>>> There are a lot of places where it should make the code clear.
>> Can you elaborate on this?
>>> I always have to create shorter aliases for the most used structs. (which i think is awkward sometimes)
>> Why? (I do not see any relation to Uniform initialization)
>
> egs:
> //D
> alias vec3 = Tuple!(float, "x", float, "y", float, "z");
> vec3[] vectors = [
>    vec3(1.0,0.0,1.0),
>    vec3(2.0,1.0,1.0),
>    vec3(3.0,2.0,1.0)
> ];
> //C++ equivalent
> vec3 vectors[] = {
>    {1.0,0.0,1.0},
>    {2.0,1.0,1.0},
>    {3.0,2.0,1.0}
> };

this works for D too:

import std.stdio;

struct S
{
    int a;
    int b;
}
void main()
{
    S[] s = [{ 1, 2 }];
    writeln(s[0]);
}
>
>
> //D
> auto return_value = get_struct(); //don´t need to write the return type
> set_struct( StructName(value1, value2) );
> //C++
> set_struct( {value1, value2} ); //don´t need to write the argument type
OK this does not work but I do not think it is releated to Uniform initialization, but it is more something like cast to parametr type or something like that
>
> Can you explain why you think is a bad idea?
Because there is no need. In c++ it is disaster because there is milion way how to initialize something, it is really hard to understand and inconsistent
October 22, 2016
S[] s = [{ 1, 2 }];

Nice, did´n knew that it worked.

On Friday, 21 October 2016 at 21:41:16 UTC, Daniel Kozak wrote:
> Because there is no need. In c++ it is disaster because there is milion way how to initialize something, it is really hard to understand and inconsistent

I never really felt lost about it with c++, but the argument holds true anyway :)
October 23, 2016
On Saturday, 22 October 2016 at 21:26:53 UTC, Patric Dexheimer wrote:
> S[] s = [{ 1, 2 }];
>
> Nice, did´n knew that it worked.
>
> On Friday, 21 October 2016 at 21:41:16 UTC, Daniel Kozak wrote:
>> Because there is no need. In c++ it is disaster because there is milion way how to initialize something, it is really hard to understand and inconsistent
>
> I never really felt lost about it with c++, but the argument holds true anyway :)

There has been a abandoned proposal for struct initialization:
https://github.com/dlang/DIPs/pull/22
October 23, 2016
On Sunday, 23 October 2016 at 01:31:47 UTC, Seb wrote:
> On Saturday, 22 October 2016 at 21:26:53 UTC, Patric Dexheimer wrote:
>> S[] s = [{ 1, 2 }];
>>
>> Nice, did´n knew that it worked.
>>
>> On Friday, 21 October 2016 at 21:41:16 UTC, Daniel Kozak wrote:
>>> Because there is no need. In c++ it is disaster because there is milion way how to initialize something, it is really hard to understand and inconsistent
>>
>> I never really felt lost about it with c++, but the argument holds true anyway :)
>
> There has been a abandoned proposal for struct initialization:
> https://github.com/dlang/DIPs/pull/22

It has been closed only because of inactivity.