nobody wrote:
"bearophile" <[email protected]> wrote in message news:[email protected]...
nobody:
BCS:
However this still has a few problems: 1, if claw contains a reference
type you will now have 2 Claws that refer to the same thing and 2, you
need to maintain opAssign to be sure that it copies all members.

One way to attack both of these would be to use a template to build a
generic deep copy that uses compile time refection to copy all the
members, duping arrays of PODS, copying basic types and recursively deep
copying reference types and arrays of them.
Guess I'll do that.
Thanks for the help!
If you create a generic deep copy I may find it useful.

Bye,
bearophile

Heh, unfortunately I wouldn't even know where to begin in order to make something like that.

Off the top of my head, it wouldn't be terribly hard.

What you would need is a global 'ddup' (deep-dup) function. The generic case would look something like:

T ddup(T)(ref T value)
{
    T result;
    foreach( i,f ; value.tupleof )
        result.tupleof[i] = ddup(f);
    return result;
}

You'd then have to use either specialisation or lots of static if's to account for reference types, allocating new memory as necessary.

Can't see any particular reason why you couldn't do it...

  -- Daniel

Reply via email to