Re: Struct initialization has no effect or error?

2019-10-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, October 2, 2019 11:48:46 PM MDT Mike Parker via Digitalmars-d- learn wrote: > On Thursday, 3 October 2019 at 04:57:44 UTC, mipri wrote: > > On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote: > >> I was trying to avoid such things since X is quite long in > >> name. Not a huge

Re: Struct initialization has no effect or error?

2019-10-02 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:57:44 UTC, mipri wrote: On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote: I was trying to avoid such things since X is quite long in name. Not a huge deal... and I do not like the syntax because it looks like a constructor call. It is a constructor

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote: I was trying to avoid such things since X is quite long in name. Not a huge deal... and I do not like the syntax because it looks like a constructor call. It is a constructor call, though. You can define your own as well: #!

Re: Struct initialization has no effect or error?

2019-10-02 Thread Brett via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:54:20 UTC, H. S. Teoh wrote: On Wed, Oct 02, 2019 at 05:37:57PM +, Brett via Digitalmars-d-learn wrote: struct X { int a; } X[1] x; x[0] = {3}; or x[0] = {a:3}; fails; This works: x[0] = X(123); Should the syntax not extend to the case

Re: Struct initialization has no effect or error?

2019-10-02 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 18:35:39 UTC, mipri wrote: On Wednesday, 2 October 2019 at 17:37:57 UTC, Brett wrote: X y = {3}; works fine. So one has to do x[0] = y; You could initialize x all at once. Complete example: import std.stdio; struct Point { int x, y; string

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:37:57 UTC, Brett wrote: X y = {3}; works fine. So one has to do x[0] = y; You could initialize x all at once. Complete example: import std.stdio; struct Point { int x, y; string toString() { import std.format : format;

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:54:20 UTC, H. S. Teoh wrote: On Wed, Oct 02, 2019 at 05:37:57PM +, Brett via Digitalmars-d-learn wrote: struct X { int a; } X[1] x; x[0] = {3}; or x[0] = {a:3}; fails; This works: x[0] = X(123); I'd knew I'd gotten the impression from

Re: Struct initialization has no effect or error?

2019-10-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 02, 2019 at 05:37:57PM +, Brett via Digitalmars-d-learn wrote: > struct X { int a; } > > X[1] x; > > x[0] = {3}; > > or > > x[0] = {a:3}; > > fails; This works: x[0] = X(123); > Should the syntax not extend to the case of array assignment? Arguably it should. But

Struct initialization has no effect or error?

2019-10-02 Thread Brett via Digitalmars-d-learn
struct X { int a; } X[1] x; x[0] = {3}; or x[0] = {a:3}; fails; Should the syntax not extend to the case of array assignment? This avoids a double copy. X y = {3}; works fine. So one has to do x[0] = y;