Flexibly sized arrays (was Re: in-parameter)
Pillsy
pillsbury at gmail.com
Mon Nov 8 11:19:47 PST 2010
Steven Schveighoffer Wrote:
> On Mon, 08 Nov 2010 13:46:52 -0500, Pillsy <pillsbury at 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
More information about the Digitalmars-d
mailing list