digitalmars.D.learn - deep copying / .dup / template object.dup cannot deduce function from argument types
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (21/21) Dec 13 2015 Hi, I just wanted to naively copy an object and used:
- Alex Parrill (5/22) Dec 13 2015 `dup` is an array method; it only works on arrays.
- rumbu (4/7) Dec 14 2015 A naive clone method for objects:
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
Dec 13 2015
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.
Dec 13 2015
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
Dec 14 2015