Thread overview |
---|
October 09, 2014 std.container.Array deep-copy? | ||||
---|---|---|---|---|
| ||||
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 |
October 09, 2014 Re: std.container.Array deep-copy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to qznc | 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? |
October 10, 2014 Re: std.container.Array deep-copy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to qznc | On Thursday, 9 October 2014 at 21:24:55 UTC, qznc wrote:
> 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?
You will just need to slice it to provide a range.
|
October 10, 2014 Re: std.container.Array deep-copy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to yazd | On Friday, 10 October 2014 at 06:27:35 UTC, yazd wrote:
> On Thursday, 9 October 2014 at 21:24:55 UTC, qznc wrote:
>> 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?
>
> You will just need to slice it to provide a range.
Like the following? That did not work.
Array!Foo y = Array!Foo(x[]);
|
October 10, 2014 Re: std.container.Array deep-copy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to qznc | > > 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 |
October 10, 2014 Re: std.container.Array deep-copy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to yazd | On Friday, 10 October 2014 at 10:32:17 UTC, yazd wrote:
>>
>> 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
yeah man.
|
October 10, 2014 Re: std.container.Array deep-copy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sag Academy | 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:
>>>
>>> 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
>
> yeah man.
You are right.
Sorry. I probably messed up my test file somehow.
|
Copyright © 1999-2021 by the D Language Foundation