Re: AA and struct with const member

2021-12-29 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 01:11:13 UTC, Stanislav Blinov wrote: Because opIndexAssign cannot distinguish at compile time between initialization and assignment: ```d Stuff[Key] aa; aa[key] = Stuff(args); // ostensibly, initialization aa[key] = otherStuff; // assignment to existing

Re: AA and struct with const member

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 02:33:08 UTC, frame wrote: On Wednesday, 29 December 2021 at 01:11:13 UTC, Stanislav Blinov wrote: Because opIndexAssign cannot distinguish at compile time between initialization and assignment: ```d Stuff[Key] aa; aa[key] = Stuff(args); // ostensibly,

Re: AA and struct with const member

2021-12-28 Thread frame via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 01:11:13 UTC, Stanislav Blinov wrote: Because opIndexAssign cannot distinguish at compile time between initialization and assignment: ```d Stuff[Key] aa; aa[key] = Stuff(args); // ostensibly, initialization aa[key] = otherStuff; // assignment to existing

Re: AA and struct with const member

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:46:16 UTC, frame wrote: On Tuesday, 28 December 2021 at 10:02:13 UTC, tsbockman wrote: // Should be a compile-time error, because it might reassign: test[key] = S(value); This might be a typo in your example but why should it be a compile-time error,

Re: AA and struct with const member

2021-12-28 Thread frame via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 10:02:13 UTC, tsbockman wrote: // Should be a compile-time error, because it might reassign: test[key] = S(value); This might be a typo in your example but why should it be a compile-time error, it cannot know if the key already exists in compile time on

Re: AA and struct with const member

2021-12-28 Thread frame via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 14:48:24 UTC, Era Scarecrow wrote: Probably better to make data private vs making it const. I tend to use const far more as input arguments to help denote it won't change references and less for elements in a struct. That or make it a class? I'm not sure.

Re: AA and struct with const member

2021-12-28 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 07:51:04 UTC, frame wrote: On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: Success! So i summarize, either work with a pointer, or drop the const... Of course casting the const away was the first thing I did but I think this is not

Re: AA and struct with const member

2021-12-28 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 07:54:56 UTC, frame wrote: On Tuesday, 28 December 2021 at 06:38:03 UTC, Tejas wrote: The workaround is okay, but I think we should file a bug report for this. This is very ~~stupid~~ undesirable behaviour I agree. I'll just wait if somebody can explain why

Re: AA and struct with const member

2021-12-27 Thread frame via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: Success! So i summarize, either work with a pointer, or drop the const... Of course casting the const away was the first thing I did but I think this is not very clean :D

Re: AA and struct with const member

2021-12-27 Thread frame via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 06:38:03 UTC, Tejas wrote: On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: On Monday, 27 December 2021 at 19:38:38 UTC, frame wrote: [...] const/immutable members are to be set/assigned instantiation. Most likely the problem is a bug and

Re: AA and struct with const member

2021-12-27 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: On Monday, 27 December 2021 at 19:38:38 UTC, frame wrote: [...] const/immutable members are to be set/assigned instantiation. Most likely the problem is a bug and sounds like [...] The workaround is okay, but I think we

Re: AA and struct with const member

2021-12-27 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 27 December 2021 at 19:38:38 UTC, frame wrote: I feel stupid right now: One cannot assign a struct that contains const member to AA? Error: cannot modify struct instance ... of type ... because it contains `const` or `immutable` members This is considered a modification? ```d

AA and struct with const member

2021-12-27 Thread frame via Digitalmars-d-learn
I feel stupid right now: One cannot assign a struct that contains const member to AA? Error: cannot modify struct instance ... of type ... because it contains `const` or `immutable` members This is considered a modification? ```d struct S { const(int) a; } S[string] test; test["a"] =