Is all this Invarient **** er... stuff, premature optimisation?

Lionello Lunesu lionello at lunesu.remove.com
Tue Apr 29 02:48:09 PDT 2008


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:fv3612$sgu$1 at digitalmars.com...
> That stuff like this compiles and seems to work is why we really need to 
> make at least one alternative version of cast.  One would be for relative 
> safe run-of-the-mill casts, like casting float to int, or casting Object 
> to some class (and checking for null),  and the other category would be 
> for dangerous big red flags kind of things like the above.  Using the 
> run-of-the-mill cast in the above situation would not be allowed.

That request has been on the "unofficial wish list" since the beginning.. 
And I still agree with it.

Maybe cast() should be parsed as a template. Then, the compiler should 
require more "!"s as the risc increases:

SomeClass sc = cast(SomeClass)some_obj;   //OK
int i = cast!(int)some_float;    //might not fit
SomeClass sc = cast!!(SomeClass)void_ptr;  //unsafe
char[] mutstring = cast!!!!!!!!(char[])toUpper("...");  //wtf are you doing!

L.





More information about the Digitalmars-d mailing list