Phobos
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Thu Mar 9 09:03:32 PST 2006
Fredrik Olsson wrote:
>>>> 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
It's not that simple. There's a good reason to allow the coder to
override default (shallow) cloning with a custom one. Not all classes
require you to clone all contents. A simple opClone-override would be
enough. A := -operator doesn't provide anything amusingly new. You can
do this already with foo.dup(). But it looks quite pretty :)
>
> 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?
No. C++ coders might get confused here.
More information about the Digitalmars-d
mailing list