From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2005-12-19 18:17:53
[Thank you Thorsten for pointing me to this]
>>> > my impression is that most of the warnings look spurious.
>>> How many warnings? what type of warning?
>> Dozens - mostly data loss on conversion, unsigned/signed,
>> untidynesses like unused parameters. I don't want to alter Moshiers
>> code at all (yet).
> well, I suggest that you do a numeric_cast in debug-mode and a
> static_cast in release-mode. That way you don't alter his code's
> behavior, but get rid of the warnings.
> We really should have something like
> asserting_numeric_cast<T>( u )
> in cast.hpp
That would range check but only in a DEBUG build right?
The problem I have with this is that it hides the fact that range checking
is disabled in a release build.
A better solution, IMO, is to use something like:
assert( is_in_range<T>(u) ) ;
T t = static_cast<T>(u) ;
which makes it clear that out of range conversions are "exceptional"
(unexpected) and so are "asserted" rather than "always checked".
The Boost Numeric Conversion Library already provides a stand alone range
checking functionality through:
numeric::converter<T,S>::out_of_range(u) == cInRange
But granted, that is far from terse... I guess the library should have a
shortcut for that in the form of template function "is_in_range<>"
I'll add that one.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk