safer casts - take II

terranium spam at here.lot
Tue May 13 12:50:10 PDT 2008


Dee Girl Wrote:

> But cast that throws is not good primitive. Because you need expensive operation to implement cast that returns null on failure.

There is only minor need for this silent cast, I believe, so 1) since this is rarely needed, performance penalty is acceptable, 2) if you don't want performance penalty, avoid need for silent cast.

> If you use cast that throws in D then you are forced in that pattern.

The unwanted one (and forced to) should be unsafe functionality, rather than safe. The type switch from your example can be implemented in a more efficient way with a type hashtable.



More information about the Digitalmars-d mailing list