Re:C++11 and Boost - Succinct like Python
by fafner on Wednesday October 31, 2012 @01:03PM
(#4723865)
I know the C-style casts are bad (although this is more of a C++-style-C-style cast. (unsigned) would have been the C-cast. But still bad). But in this situation it should be safe and for use in an example more readable.
btw. Please fix either the size of your code or the margins of your blog. You use only half the screen width but I still have to scroll sideways in the code listing.
Re:C++11 and Boost - Succinct like Python
by mikeash on Wednesday October 31, 2012 @06:46PM
(#4725279)
How can a C-style cast from char to unsigned possibly be "less safe", and how could a different style of cast be more safe?
Re:C++11 and Boost - Succinct like Python
by daivd on Thursday November 01, 2012 @06:15AM
(#4726865)
In this case it obviously doesn't matter, but in the general case it is better to be explicit on which type of cast you are doing. That way the compiler can statically stop you from doing stupid things. Read the link I gave.
The C-style cast is shorter, but less safe, so you should not use it: http://stackoverflow.com/questions/1609163/what-is-the-diffe...
Yeah, I couldn't quite decide if I should include const refs. On the one hand, it is idiomatic, but on the other hand I didn't want to clutter the code with something that is just an optimization on paper.