DMD 2.000 alpha release

Walter Bright newshound1 at digitalmars.com
Mon Jun 18 13:53:02 PDT 2007


Johan Granberg wrote:
> I don't think invariant here is such a great idea, consider the following
> function.
> 
> void foo(string s){}
> 
> if string is const this can be called with both char[] and const(char)[] (if
> not please correct me) but if my understanding is correct char[] would not
> work if string is invariant. This will lead to an unessesary amount of
> cast(invariant) when calling functions on local strings (as functions that
> create strings will have to modify the when they are being built).

That's essentially my argument against it, too. The other side is that 
treating strings as if they are value types is common and effective in 
other languages. (For example, strings in Perl are invariant.)

One of the reasons for adding .idup is to reduce the need to cast to 
invariant.



More information about the Digitalmars-d-announce mailing list