automatic conversion to invariant (string?)

Yossarian xtauer01 at stud.fit.vutbr.cz
Thu Mar 20 07:52:12 PDT 2008


Dne Thu, 20 Mar 2008 12:05:44 +0100 Janice Caron <caron800 at googlemail.com>  
napsal/-a:

> On 20/03/2008, Yossarian <xtauer01 at stud.fit.vutbr.cz> wrote:
>>  wouldn't
>>  this 'downcast' be logical?'
>
> No. Example:
>
>     char[] s = cast(char[]) "hello";
>     string t = s;
>     s[0] = 'j';
>
> There's a good reason why that won't compile!
>
> Both mutable and invariant will downcast to const, so from const to
> either mutable or invariant is an upcast. That makes going from
> mutable to invariant a "sideways cast"


i think that
char[] s = "hello" ; // this should compile without explicit cast. imho.  
the cast should be like ("hello".dup),
			// int[] c = [3, 5]; compiles.

string t = s; 		// wouldn't it be logical to use not copy-on-write, but  
initialize new string with old char[]?
s[0] = 'j';		// change only s, not t.


-- 
Tato zpráva byla vytvořena převratným poštovním klientem Opery:  
http://www.opera.com/mail/



More information about the Digitalmars-d mailing list