T[new]

Jeremie Pelletier jeremiep at gmail.com
Mon Aug 10 10:01:56 PDT 2009


Lars T. Kyllingstad Wrote:

> Walter Bright wrote:
> > Lars T. Kyllingstad wrote:
> >> I've always wondered: Why are strings of type immutable(char)[], and 
> >> not immutable(char[])?
> > 
> > So:
> > 
> >    string a = "hello";
> >    a = "foo";
> > 
> > works.
> 
> 
> Ah, of course. :) Thanks.
> 
> -Lars

The problem with immutable(char)[] was that any string can be resized, even slices.

Walter: what will the string types be aliased to now: still immutable(char)[] or immutable(char)[new]?

I think it would be best to have them use the array [new] type. Functions which do not modify the string length can mark the string as an in parameter, and immutable(char)[] should be castable to const(immutable(char)[new]) in such cases to still allow slices to be passed.



More information about the Digitalmars-d mailing list