
AMDG Hermann Rodrigues wrote:
I agree with you that testing the value in numeric_cast is a bad thing. But I think that numeric_cast is not delivering what it advertises. For me a well formed cast is always one where A can be converted to B and back to A without any lose in the representation. Unfortunately, with the current implementation A (an integer) can be converted to B (a float) but the resulting value can not be casted back to an integer representing A.
numeric_cast is doing exactly what it is supposed to. It makes sure that the source value is within the range of the destination type. If it required reversibility, then conversion from double to float would almost always fail, for example.
Maybe It is a good idea to provide an additional implementation of a function similar to numeric_cast (say strict_numeric_cast) behaving like that.
In Christ, Steven Watanabe