automatic conversion to invariant (string?)

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Mar 25 07:47:44 PDT 2008


Janice Caron wrote:
> 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"

Just for the sake of pendanticness, you're switching/mixing up the terms 
"downcast" and "upcast", it should be the other way around:
"Both mutable and invariant will upcast to const, so from const to 
either mutable or invariant is an downcast."
becausing upcasting is generelly the safe cast (less specific), while 
downcasting is the unsafe cast (more specific).


-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list