Phobos

Fredrik Olsson peylow at treyst.se
Thu Mar 9 08:02:06 PST 2006


James Dunne skrev:
> Georg Wrede wrote:
>> Ben Phillips wrote:
>>
>>> In article <dune2o$cu4$1 at digitaldaemon.com>, Def says...
>>>
>>>> Array op= operations are not implemented.
>>>
>>>
>>> This has been discussed numerous times and the consensus is that
>>> overloading "=" is a bad idea. You must remember that D uses
>>> references so if we have a class and two instances ("a" and "b") then
>>> "a = b;" makes "a" refer to the same object as "b". The programmer
>>> should not be allowed to change this behavior.
>>>
>>> On the other hand, another operator such as ":=" has been suggested
>>> which would be a copy operator rather than an assignment operator
>>
>>
>> It would definitely stand out in code better than a .dup swamped 
>> somewhere inconspicuous.
> 
> But you lose all meaning as to if that dup is a shallow copy or deep copy.
> 
:= shallow copy
::= deep copy

:)

But how to solve for example "foo(bar.dup);"? Perhaps not a critical 
flaw, but something could be useful if you know that foo will corupt the 
input. "foo(:bar);", and "foo(::bar);" would be the logical answers but 
not as pretty, or?

// Fredrik



More information about the Digitalmars-d mailing list