Behaviour of append (~=)
Oskar Linde
oskar.lindeREM at OVEgmail.com
Tue May 30 08:17:09 PDT 2006
(I posted another thing to this thread that I later canceled. It was
just me misunderstanding what Derek meant. I'm just too tired right now...)
Lionello Lunesu skrev:
> I don't think those programmers should write code that depends on the
> compiler copying the data in those cases. You got the array you asked
> for, so? If you want to make sure have a copy, you probably needed to
> .dup yourself anyway.
I would put it the other way around. IMHO, the more guarantees the
language can give you the better. Defensive .dup-ing is never good.
D doesn't have any notion of ownership, you have to remember what you
own and what you don't. Currently, if you create an array and add
(append) data to it, you are guaranteed that you still own the data.
With your suggestion, that would no longer be true.
It is very common to append data that you don't own:
a ~= "static read-only string constant";
or
a ~= itoa(7); // May refer to static string data.
/Oskar
More information about the Digitalmars-d-learn
mailing list