Taking a copy of an object
Hasan Aljudy
hasan.aljudy at gmail.com
Thu Aug 3 16:12:39 PDT 2006
Derek wrote:
> On Thu, 03 Aug 2006 14:12:03 -0600, Hasan Aljudy wrote:
>
>
>>Bruno Medeiros wrote:
>>
>>>Derek Parnell wrote:
>>>
>>
>><Snip>
>>
>>>>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.
>>>>
>>>
>>>Yes, I think that would be quite useful.
>>>
>>
>>Oh please, I hate the := operator, it's too ugly.
>
>
> I don't give a damn what operator is used, this was *JUST AN EXAMPLE*.
>
> 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.
>
why an operator?
a method/property is more suitable, I think.
More information about the Digitalmars-d
mailing list