std.conv.to vs. casting

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Thu Jul 4 02:31:23 PDT 2013


On 07/04/2013 10:14 AM, monarch_dodra wrote:
> Casting merely changes the "observed type", whereas "to" does a deep conversion.

What are the speed implications of to compared to cast?

I ask because I see various casts in Phobos, and wonder if there isn't improved
safety in preferring instead to use to, so long as the optimal speed is there
with appropriate compiler optimizations.

I'm particularly concerned here because of a bug I observed that would have been
caught if to had been used rather than cast:
http://d.puremagic.com/issues/show_bug.cgi?id=10322#c4

(I'm working on a fix, it's just time constraints that have delayed delivering it:-)


More information about the Digitalmars-d-learn mailing list