D - more or less power than C++?

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Sun Mar 5 12:28:38 PST 2006


Bruno Medeiros wrote:
> Derek Parnell wrote:
>> <Ben_member at pathlink.com> wrote:
>>> Imho, we just need a standardized "clone" method (like .dup) that can
>>> be used
>>> for assigning.
>>
>> YES! And a syntax to support opDup().  The "=" means assign, so why
>> not have another operator to mean
>> copy-the-data-not-just-the-reference? ":=" has been suggested but
>> there could be other great ideas.
>>
> 
> Hum, yes!, ideally we could two pairs of operators, each for
> setting/testing the reference/instance_data
> 
> =    Assign the reference to an object (currently: = )
> ==    Test for identity, aka same reference (currently: is )
> :=    Copy the object. (nothing similar)
> :==    Test for equality, aka same instance data ( currently: == )
> 
> This is just the structural idea, the name/symbols of these operators
> could be something other and better (and I think this choice would be a
> very important aspect of this feature).
> 
> 

I think these have been proposed few times before. The existence of a
"standardized" dup or clone that can be overridden is extremely
important now that we aren't (thank God) able to overload standard
assignment operator '='. How else would it be possible to 'deep clone'
classes clearly?

I like the ':=' as a copy/assign operator. However currently '==' is
semantically closer to '==' with basic types (ints, chars, ...) because
it compares the contents and not references. I think 'is' and '==' both
should stay and not introduce a new ':==' - it doesn't look very cute on
all editors either.

-- 
Jari-Matti



More information about the Digitalmars-d mailing list