Steven Schveighoffer Wrote:

> On Mon, 08 Nov 2010 13:46:52 -0500, Pillsy <pillsb...@gmail.com> 
> wrote:

> > Besides, isn't catenating or appending in place impossible with D's  
> > (immutable) strings anyway?

> This is a misconception, a string is not immutable, the data it points 
> to is immutable.  You can append to a string just like a mutable array.

So, wait, if I have a program like this:

void appendSailor (string s) {
   s ~= "Sailor";
}

void main () {
   auto s = "Hello World!";

   appendSailor(s[0 .. 6]);

   writefln(s);
}

I should expect to get "Hello Sailor" as output? Or is it just that a new array 
of characters will be allocated and that will be appended into, so 
`appendSailor()` becomes a slightly expensive no-op?

The former behavior would be really horrible, while the latter behavior doesn't 
seem to provide an overwhelming advantage over not allowing append-in-place for 
arrays.

Cheers,
Pillsy

Reply via email to