digitalmars.D.learn - std.container.Array deep-copy?
- qznc (19/19) Oct 09 2014 How can you deep-copy a std.container.Array instance?
- qznc (4/5) Oct 09 2014 Ok, the deep-copy problem already got resolved on reddit: Use dup.
- yazd (2/9) Oct 09 2014 You will just need to slice it to provide a range.
- qznc (3/14) Oct 10 2014 Like the following? That did not work.
- yazd (2/4) Oct 10 2014 How does it not work?
- Sag Academy (2/8) Oct 10 2014 yeah man.
- qznc (3/12) Oct 10 2014 You are right.
How can you deep-copy a std.container.Array instance? The actual array data is heap-allocated and reference-counted. Assignment and .dup only create additional references. Using a copy constructor yields an error: Array!Foo x; Array!Foo y = Array!Foo(x); Error: template std.container.Array!(Foo).Array.__ctor cannot deduce function from argument types !()(Array!(Foo)), candidates are: /opt/compilers/dmd2/include/std/container.d(2652): std.container.Array!(Foo).Array.__ctor(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) /opt/compilers/dmd2/include/std/container.d(2670): std.container.Array!(Foo).Array.__ctor(Stuff)(Stuff stuff) if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T) && !is(Stuff == T[])) The question came up in a reddit discussion: http://www.reddit.com/r/programming/comments/2ipdpa/floss_weekly_311_the_d_language/cl4yv8w
Oct 09 2014
On Thursday, 9 October 2014 at 21:14:46 UTC, qznc wrote:How can you deep-copy a std.container.Array instance?Ok, the deep-copy problem already got resolved on reddit: Use dup. However, the error is still open. You cannot give an Array!X argument to constructor/replace/insertBefore of Array!X instances?
Oct 09 2014
On Thursday, 9 October 2014 at 21:24:55 UTC, qznc wrote:On Thursday, 9 October 2014 at 21:14:46 UTC, qznc wrote:You will just need to slice it to provide a range.How can you deep-copy a std.container.Array instance?Ok, the deep-copy problem already got resolved on reddit: Use dup. However, the error is still open. You cannot give an Array!X argument to constructor/replace/insertBefore of Array!X instances?
Oct 09 2014
On Friday, 10 October 2014 at 06:27:35 UTC, yazd wrote:On Thursday, 9 October 2014 at 21:24:55 UTC, qznc wrote:Like the following? That did not work. Array!Foo y = Array!Foo(x[]);On Thursday, 9 October 2014 at 21:14:46 UTC, qznc wrote:You will just need to slice it to provide a range.How can you deep-copy a std.container.Array instance?Ok, the deep-copy problem already got resolved on reddit: Use dup. However, the error is still open. You cannot give an Array!X argument to constructor/replace/insertBefore of Array!X instances?
Oct 10 2014
Like the following? That did not work. Array!Foo y = Array!Foo(x[]);How does it not work? It compiles successfully: http://dpaste.dzfl.pl/583d20e426a0
Oct 10 2014
On Friday, 10 October 2014 at 10:32:17 UTC, yazd wrote:yeah man.Like the following? That did not work. Array!Foo y = Array!Foo(x[]);How does it not work? It compiles successfully: http://dpaste.dzfl.pl/583d20e426a0
Oct 10 2014
On Friday, 10 October 2014 at 10:59:59 UTC, Sag Academy wrote:On Friday, 10 October 2014 at 10:32:17 UTC, yazd wrote:You are right. Sorry. I probably messed up my test file somehow.yeah man.Like the following? That did not work. Array!Foo y = Array!Foo(x[]);How does it not work? It compiles successfully: http://dpaste.dzfl.pl/583d20e426a0
Oct 10 2014