Taking a copy of an object

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Tue Aug 8 07:39:50 PDT 2006


Derek wrote:
> 
>> Also, it is redundant to specify a shallow copy function for each class: 
>> the code is the same for any class. It is something like:
>>    Object ShallowCopy(Object obj) {
>>      int len = obj.classinfo.init.length;
>>      auto data = (cast(ubyte*) obj)[0..len];
>>      return cast(Object) data.dup.ptr;
>>    }
>> So there should not be two different functions for each kind of copy, 
>> there should be only one, which conceptually is defined to do a deep copy.
> 
> Not sure I agree here. The shallow copy coulod be generic as you
> demonstrated, but a deep copy is very Object-specific and would need to be
> defined in the class that needed it. 
> 
> 

I quite agree with what you said, I misstated my comments: when I said 
"there should not be two different functions", by 'functions' I meant 
"functions defined by the user". That is, there should not be two 
different functions defined by the user, as the shallow copy one is 
redundant, and should exist already.

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



More information about the Digitalmars-d mailing list