Re: Struct immutable data and dict

2018-09-04 Thread Timoses via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 12:27:47 UTC, nkm1 wrote: I also had this problem recently. I think aa.require() should allow to add immutables (feature request). Anyway, my workaround was along the lines of: final class AA(Key, Value) { Value[] _storage; size_t[Key] _aa; void opI

Re: Struct immutable data and dict

2018-09-04 Thread nkm1 via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 11:25:15 UTC, Alex wrote: On Tuesday, 4 September 2018 at 10:30:24 UTC, Timoses wrote: However, of course this also fails because randomly assigning the array elements will overwrite it. So the associative array seems like the better idea. However, not being ab

Re: Struct immutable data and dict

2018-09-04 Thread Alex via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 10:30:24 UTC, Timoses wrote: However, of course this also fails because randomly assigning the array elements will overwrite it. So the associative array seems like the better idea. However, not being able to INITIALIZE an assoc array element disallows its usag

Re: Struct immutable data and dict

2018-09-04 Thread Timoses via Digitalmars-d-learn
On Thursday, 6 October 2016 at 02:09:44 UTC, Adam D. Ruppe wrote: On Thursday, 6 October 2016 at 01:23:35 UTC, Patric Dexheimer wrote: Why? Because you'd be overwriting that immutable member. Structs just put structure around their contents, but it doesn't change their nature. That struct is

Re: Struct immutable data and dict

2016-10-06 Thread Patric Dexheimer via Digitalmars-d-learn
On Thursday, 6 October 2016 at 03:48:22 UTC, Mike Parker wrote: On Thursday, 6 October 2016 at 03:05:18 UTC, Patric Dexheimer wrote: [...] There's a difference between initialization and assignment. [...] On Thursday, 6 October 2016 at 03:48:22 UTC, Mike Parker wrote: On Thursday, 6 Octobe

Re: Struct immutable data and dict

2016-10-05 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 6 October 2016 at 03:05:18 UTC, Patric Dexheimer wrote: But why i´m overwriting the struct if its the first time i´m putting it there? (like on the array). There's a difference between initialization and assignment. ``` // Given this structure struct MyStruct { int x; } // Both

Re: Struct immutable data and dict

2016-10-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 October 2016 at 03:05:18 UTC, Patric Dexheimer wrote: But why i´m overwriting the struct if its the first time i´m putting it there? (like on the array). The compiler doesn't know it is the first time (it doesn't follow the data from creation, it just looks at that individual li

Re: Struct immutable data and dict

2016-10-05 Thread Patric Dexheimer via Digitalmars-d-learn
On Thursday, 6 October 2016 at 02:09:44 UTC, Adam D. Ruppe wrote: On Thursday, 6 October 2016 at 01:23:35 UTC, Patric Dexheimer wrote: Why? Because you'd be overwriting that immutable member. Structs just put structure around their contents, but it doesn't change their nature. That struct is

Re: Struct immutable data and dict

2016-10-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 October 2016 at 01:23:35 UTC, Patric Dexheimer wrote: Why? Because you'd be overwriting that immutable member. Structs just put structure around their contents, but it doesn't change their nature. That struct is no different than if you wrote `immutable size_t` as the value -

Struct immutable data and dict

2016-10-05 Thread Patric Dexheimer via Digitalmars-d-learn
struct Test{ immutable size_t id; } Test[string] dict; Test[] array; void main(){ array~=Test(1);//work dict["teste"] = Test(1); //fail ?? } "Error: cannot modify struct dict["teste"] Test with immutable members" Why?