digitalmars.D - D Uniform initialization {}
- Patric Dexheimer (10/10) Oct 21 2016 Quite sure that this was already discussed, but.. any chance of
- Daniel Kozak via Digitalmars-d (4/9) Oct 21 2016 Can you elaborate on this?
- Patric Dexheimer (33/44) Oct 21 2016 egs:
- Daniel Kozak via Digitalmars-d (19/51) Oct 21 2016 this works for D too:
- Patric Dexheimer (5/8) Oct 22 2016 S[] s = [{ 1, 2 }];
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 :)
Oct 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)
Oct 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):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?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)
Oct 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:this works for D too: import std.stdio; struct S { int a; int b; } void main() { S[] s = [{ 1, 2 }]; writeln(s[0]); }Dne 21.10.2016 v 20:49 Patric Dexheimer via Digitalmars-d napsal(a):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} };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)//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 typeOK 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 thatCan 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
Oct 21 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 inconsistentI never really felt lost about it with c++, but the argument holds true anyway :)
Oct 22 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:There has been a abandoned proposal for struct initialization: https://github.com/dlang/DIPs/pull/22Because 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 inconsistentI never really felt lost about it with c++, but the argument holds true anyway :)
Oct 22 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:It has been closed only because of inactivity.S[] s = [{ 1, 2 }]; Nice, did´n knew that it worked. On Friday, 21 October 2016 at 21:41:16 UTC, Daniel Kozak wrote:There has been a abandoned proposal for struct initialization: https://github.com/dlang/DIPs/pull/22Because 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 inconsistentI never really felt lost about it with c++, but the argument holds true anyway :)
Oct 22 2016