Taking a copy of an object

Hasan Aljudy hasan.aljudy at gmail.com
Thu Aug 3 16:12:06 PDT 2006



Tom S wrote:
> Derek wrote:
> 
>> On Thu, 03 Aug 2006 14:26:08 +0100, Bruno Medeiros wrote:
>>
>>> Derek Parnell wrote:
>>>
>>>> Currently there doesn't seem to be any standard D mechanism (read:
>>>> operator) to take a copy of an object. So are there any suggestions 
>>>> for a
>>>> name that we can all agree on; one that might become an unofficial
>>>> standard?
>>>> For arrays we have the 'dup' property but for objects there is 
>>>> nothing that
>>>> the compiler assumes. I'm partial to 'onDup' or 'onCopy', and maybe 
>>>> even a
>>>> 'onDeepCopy' as an additional function.
>>>>
>>>> Example:
>>>>
>>>>   class Foo
>>>>   {
>>>>       int x;
>>>>       Bar b;
>>>>
>>>>       this(int y)       {
>>>>            x = y;
>>>>            b = new Bar(y);
>>>>       }
>>>>
>>>>       Foo onCopy()
>>>>       {
>>>>           Foo t;
>>>>           t = new Foo(x);
>>>>           return t;
>>>>        }
>>>>    }
>>>>
>>>>    . . .
>>>>    auto backup = q.onCopy();
>>>>
>>> What's the "on" prefix for? I think the name should be something like:
>>
>>
>> The 'on' prefix is a *hint* to Walter that I'd really like this 
>> function to
>> be invoked via a new operator and not necessariliy called directly.
> 
> 
> 
> Somehow, 'on' doesn't sound like an operator. On the other hand 'op' 
> does...

I think he meant op ..
heheh .. when I first read the specs on operator overloading I got 
confused and, in my mind, I read all the opXxxx functions as onXxxx



More information about the Digitalmars-d mailing list