safer casts - take II

Bill Baxter dnewsgroup at billbaxter.com
Tue May 13 14:11:04 PDT 2008


Yigal Chripun wrote:
> since the other thread got completely off-topic and lost any connection
> to the original discussion, here's a new clean thread, that will
> hopefully summarize the previous discussion and present the latest
> proposal so that hopefully more people join the debate without the need
> to go through all the previous posts (164 posts!).
> 
> Here goes:
> 
> the proposal is for a safer cast that will _replace_ the current cast.
> this is important both for a consistent syntax and to prevent subverting
> the system with the old style cast.
> 
> there are there forms of cast:
> (a) cast(T)something
> (b) cast!(T)something

No no.   "super cast(T)something" is what you're looking for.  :-) [1]


> (c) reinterpret_cast!(T)

Seriously, though, it sounds good to me.  My initial impression was that 
basically we needed just one alternative form of cast.  Leave cast(T) 
for the "yes I'm casting but it's not a big deal" forms, and make some 
new form for the "Lookout!  Crazy guy with a cast who's not afraid to 
use it, here!"   And that's pretty much what you folks seem to have 
settled on.  (Discounting the third form, reinterpret_cast, since it's 
just a library function -- but a good one to have, I'll agree)

[1] (For those who don't recall "invariant" was slated to be called 
"super const" for a while...)

--bb



More information about the Digitalmars-d mailing list