March 20, 2008 Re: automatic conversion to invariant (string?) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Yossarian | Yossarian wrote: > Dne Thu, 20 Mar 2008 15:56:01 +0100 Janice Caron <caron800@googlemail.com> napsal/-a: > >> On 20/03/2008, Yossarian <xtauer01@stud.fit.vutbr.cz> wrote: >>> but string is invariant(char)[]. and that's problem for me, because some >>> of the standard libraries aren't ready for this. >> >> Specifically, which ones? > > > I can't, for example do this: > throw new Error("This is an text of error"); I'm pretty sure you can, actually. You can't do it with a char[] parameter, but literals have invariant characters already and should work fine. > I must do > throw new Error(cast(string)"This is an text of error"); String literals implicitly convert to string, so the cast is completely unnecessary. | |||
March 25, 2008 Re: automatic conversion to invariant (string?) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | Janice Caron wrote: > On 20/03/2008, Yossarian <xtauer01@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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply