Matter of style, and cast()

Jonathan M Davis jmdavisProg at gmx.com
Mon Aug 5 12:03:37 PDT 2013


On Monday, August 05, 2013 15:46:13 Joseph Rushton Wakeling wrote:
> On 08/05/2013 03:01 PM, bearophile wrote:
> > 2) The code should contain as few cast() as possible. [*]
> 
> What about to!() ... ? Is it possible to gain the performance of cast()
> while using to!() ... ?

That depends. In general, no. std.conv.to specifically checks stuff like integer 
overflow, whereas the built-in casts speficilally don't. So, in general, you'll 
incur a slight performance penalty when using std.conv.to (though exactly how 
expensive it is depends on what is being converted to what). For a lot of code 
though, that performance hit will be so negligible, that it won't matter. It 
_will_ be there though.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list