|
Boost : |
From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2005-04-19 02:32:32
Currently following situation does not generate a bad_numeric_cast.
<test>
unsigned int ui = std::numeric_limits< unsigned int >::max() ;
int i = boost::numeric_cast< int >( ui ) ;
</test>
Nevertheless 'i' is -1 instead of some very big number. To catch this
kind of error, I propose to apply following patch to boost/cast.hpp (in
attachment).
The current implementation casts the value for to the target-type and
back to the original type and verifies that it is still the same value.
For the example above, the intermediate result will be -1 although
casting it back to the original type will result in the original value.
So the patch verifies that this intermediate result will not be negative.
If the patch is accepted I will also add a test in the current
regression-test of numeric_cast.
toon
-- Check out our training program on acoustics and register on-line at http://www.fft.be/?id=35
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk