Re: deep copying a struct

2019-09-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 September 2019 at 10:52:43 UTC, aliak wrote: On Friday, 6 September 2019 at 10:37:16 UTC, aliak wrote: Are there any library APIs that allow this: I just put this together. Any holes other the AA related ones? string a = "hello"; string b = a.dupDeep; // Error: cannot implicitly

Re: deep copying a struct

2019-09-06 Thread aliak via Digitalmars-d-learn
On Friday, 6 September 2019 at 10:37:16 UTC, aliak wrote: Are there any library APIs that allow this: I just put this together. Any holes other the AA related ones? Will it work with classes? auto dupDeep(T)(ref T thing) { import std.range: ElementType; import std.traits: hasAliasing,

deep copying a struct

2019-09-06 Thread aliak via Digitalmars-d-learn
Are there any library APIs that allow this: struct S { int[] arr; } void main() { const a = S([1,2,3]); S b = a.copy; // deep dup/copy } I'd also like to avoid implementing a copy constructor for each type.