Qian Xu wrote:
grauzone wrote:
newobject.tupleof[i] = old.tupleof[i];
If the current value of tupleof[i] is an object, the object will be
referenced, won't it?
Shall I write:
auto elem = old.tupleof[i];
static if (is(typeof(elem) == class))
{
newobject.tupleof[i] = clone(elem);
}
else
{
newobject.tupleof[i] = elem;
}
Object graphs often contain circular references liker this:
class A {
B b;
}
class B {
A a;
}
auto a = new A();
auto b = new B();
a.b = b;
b.a = a;
Your recursive approach wouldn't quite work with that. Before cloning an
object, you'll first have to check if the object was already cloned. If
this is the case, use the previously created clone instead of making a
new clone.
--Qian