Taking a copy of an object

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Tue Aug 8 13:51:44 PDT 2006


kris wrote:
> Bruno Medeiros wrote:
>> Derek wrote:
>>
>>> On Thu, 03 Aug 2006 14:12:03 -0600, Hasan Aljudy wrote:
>>>
>>>
>>> Please, feel free to suggest other things that might be suitable for a
>>> deep-copy operator. One that would be usable on all data types and 
>>> meants
>>> that the information in the left-hand-side thingy would be copied and 
>>> the
>>> right-hand thingy would 'hold' that copy.
>>>
>>> For objects, it would invoke onDup/onCopy/onClone/onDeepCopy/onWhatever
>>> (the name doesn't matter) if it existed, otherwise its a compile time
>>> error. The function would return the same datatype as the object that 
>>> owns
>>> the function, meaning that Foo.onDup can't return a Bar or its parent 
>>> type
>>> or an interface - it must return a Foo object instance.
>>>
>>> For arrays it is identical to the .dup property.
>>>
>>> For basic datatypes it is identical to moving the bit value from one to
>>> another variable (no conversion or transformations allowed).
>>>
>>> Therefore the lefthand side and righthand side thingy must be the same
>>> datatype.
>>>
>>
>> I've just realized a little nuance that both I and the rest of us are 
>> tripping on: There are two similar but distinct notions of a copy 
>> operation, not just one.
> 
> 
> Speak for yourself, Bruno: all of this is simply taken for granted in 
> some of the other posts.
> 
> 

I was writing a reply in how that was not so, and people where blending 
the two things, but... Whoa! I just realized you are right, I was way 
off-course and I've been misunderstanding this thread since the 
beginning. To make sure, going back:

Derek Wrote:
[...]
> 
> And maybe one day (hoping against precedent) that Walter will actually see
> that an operator for copying stuff is not such a stupid idea.
> 
>    auto backup := q; // invokes q.onCopy() if it exists.

Note the last paragraph. What would "auto backup := q;" do? Would it be 
the same as:
   auto backup = q.onCopy()
right? Then yes, I've seriously misunderstood it, but I think I had some 
reasons to, I'll comment later.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list