Re: What is special about an immutable array of class objects, and why can I not .dup ?

2018-05-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/28/18 9:51 AM, James Blachly wrote: Why are the class objects special in this case, and why does `immutable(C)[]` not help?   I believed that this defined a dynamic array `c` which was itself mutable, the elements of which were immutable. To build on what others have said, the key thing

Re: What is special about an immutable array of class objects, and why can I not .dup ?

2018-05-28 Thread bauss via Digitalmars-d-learn
On Monday, 28 May 2018 at 13:51:49 UTC, James Blachly wrote: Consider the below: ``` class C { int x; } struct S { int x; } void main() { immutable C[] c = [ new C(), new C()]; immutable S[] s = [ S(), S() ]; immutable int[] i = [ 1, 2 ]; auto x = c.dup;

Re: What is special about an immutable array of class objects, and why can I not .dup ?

2018-05-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, May 28, 2018 13:51:49 James Blachly via Digitalmars-d-learn wrote: > Consider the below: > > ``` > class C > { > int x; > } > > struct S > { > int x; > } > > > void main() > { > immutable C[] c = [ new C(), new C()]; > immutable S[] s = [ S(), S() ]; > immutable

What is special about an immutable array of class objects, and why can I not .dup ?

2018-05-28 Thread James Blachly via Digitalmars-d-learn
Consider the below: ``` class C { int x; } struct S { int x; } void main() { immutable C[] c = [ new C(), new C()]; immutable S[] s = [ S(), S() ]; immutable int[] i = [ 1, 2 ]; auto x = c.dup; auto y = s.dup; auto z = i.dup; } ``` This fails to