Thread overview | |||||
---|---|---|---|---|---|
|
December 13, 2015 deep copying / .dup / template object.dup cannot deduce function from argument types | ||||
---|---|---|---|---|
| ||||
Hi, I just wanted to naively copy an object and used: a = myobj.dup; and get the following error messages: source/app.d(191): Error: template object.dup cannot deduce function from argument types !()(BlockV), candidates are: /Library/D/dmd/src/druntime/import/object.d(1872): object.dup(T : V[K], K, V)(T aa) /Library/D/dmd/src/druntime/import/object.d(1908): object.dup(T : V[K], K, V)(T* aa) /Library/D/dmd/src/druntime/import/object.d(3246): object.dup(T)(T[] a) if (!is(const(T) : T)) /Library/D/dmd/src/druntime/import/object.d(3262): object.dup(T)(const(T)[] a) if (is(const(T) : T)) /Library/D/dmd/src/druntime/import/object.d(3273): object.dup(T : void)(const(T)[] a) Hmm... so, is .dup not the way to go? And, am I correct, that a deep-copy needs to be hand coded? -- Robert M. Münch http://www.saphirion.com smarter | better | faster |
December 13, 2015 Re: deep copying / .dup / template object.dup cannot deduce function from argument types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert M. Münch | On Sunday, 13 December 2015 at 18:54:24 UTC, Robert M. Münch wrote:
> Hi, I just wanted to naively copy an object and used:
>
> a = myobj.dup;
>
> and get the following error messages:
>
> source/app.d(191): Error: template object.dup cannot deduce function from argument types !()(BlockV), candidates are:
> /Library/D/dmd/src/druntime/import/object.d(1872): object.dup(T : V[K], K, V)(T aa)
> /Library/D/dmd/src/druntime/import/object.d(1908): object.dup(T : V[K], K, V)(T* aa)
> /Library/D/dmd/src/druntime/import/object.d(3246): object.dup(T)(T[] a) if (!is(const(T) : T))
> /Library/D/dmd/src/druntime/import/object.d(3262): object.dup(T)(const(T)[] a) if (is(const(T) : T))
> /Library/D/dmd/src/druntime/import/object.d(3273): object.dup(T : void)(const(T)[] a)
>
> Hmm... so, is .dup not the way to go?
>
> And, am I correct, that a deep-copy needs to be hand coded?
`dup` is an array method; it only works on arrays.
Structs are value types, so `a = b` will "duplicate" a struct. For classes, you will need to define your own clone function.
|
December 14, 2015 Re: deep copying / .dup / template object.dup cannot deduce function from argument types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert M. Münch | On Sunday, 13 December 2015 at 18:54:24 UTC, Robert M. Münch wrote: > Hi, I just wanted to naively copy an object and used: > > a = myobj.dup; > > [...] A naive clone method for objects: https://github.com/rumbu13/sharp/blob/c34139449a078618e807a3f206541656df1bea6a/src/system/package.d#L46 |
Copyright © 1999-2021 by the D Language Foundation