safer casts - take II
terranium
spam at here.lot
Tue May 13 11:36:11 PDT 2008
Janice Caron Wrote:
> Could you be a bit more specific?
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=71111
my proposal would be to make cast safer
1) throw InvalidCastException on invalid cast
2) keep const
const_cast, dynamic_cast, static_cast, reinterpret_cast templates can be implemented using this safe cast, they can be inefficient and ugly - it's normal, because they normally should not be used.
This will break existing code a little
1) if(auto x=cast(X)y) will probably throw in a predicted location, workaround - when porting, replace cast with dynamic_cast template (which should be provided by standard library for porting legacy code)
2) won't compile if mutability is used - easy to fix.
More information about the Digitalmars-d
mailing list