Copy constructor in D. Why it is necessary to have it.

KennyTM~ kennytm at gmail.com
Wed Oct 1 01:20:42 PDT 2008


Bill Baxter wrote:
> On Wed, Oct 1, 2008 at 5:55 AM, bearophile <bearophileHUGS at lycos.com> wrote:
>> Bill Baxter:
>>> It has been pointed out though, that dup is a "shallow copy" in D's
>>> built-in usage.  If you want a deep copy operation, there is no
>>> precedent in the base language, I believe.  Clone is a good one to
>>> standardize on for deep copies, I think.
>> I see.
>> Probably the more readable & intuitive names are "copy" and "deepcopy". But "dup" is already present, so it has to be accepted, I presume.
>> What about "deepdup" for the deep version instead? :-)
> 
> Heh,  made me think .deeppoop when I first saw that.
> 
>> It's more easy to remember its meaning (and I presume it's not that commonly used to deserve a very short name).
> 
> I like clone.  It's used pretty commonly in other languages.  I'd
> rather not follow up one slightly odd-ball name with an even more
> bizarre one.  But it's not gonna be anything more than a convention
> anyway, so you're free to name it .deepdup if you like in your
> libraries.
> 
> --bb

I use .clone also, but the difference in meaning between .clone and .dup 
may not be clear enough to say the former is a deep copy but the latter 
is shallow.

Ouch, but we have invariant vs const already, so maybe it's OK. /sarcasm



More information about the Digitalmars-d mailing list