Hi &rzej,
Thanks for all the comments, very helpful.
I think passing the reporting method to the check makes sense and helps
having uniformity at the interface level. Something I'm wondering is if
safe_float should receive only 1 policy (that could be composed, this is
what I have implemented now) or if I should use variadic template and allow
to pass multiple pass as many policies as wanted and make their composition
internally.
Something like:
safe_float;
vs
safe_float
I'm also implementing a convenience.hpp with compositions of policies that
may be common to mix, for example, I define both_flows as the check of both
underflow and overflows.
About division by zero. The following code compiles with no warning in
clang (-wall -pedatic).
float a = 1.0f;
float b = numeric_limits::max();
float c = a/b;
float d = c/b;
float e = a/d;
I'm not sure if there is any static analyzer that will catch that the flag
of div_by_zero is on after last operation, and probably there is even less
chance that this is catched if d and e are in different cpp files or one is
coming from user input as cin. Do you know about such a tool that will
catch things like this?
About the casts, I'm including cast policies for casts too, I calling them
allow_cast_from<T> and allow_cast_to<T>, by default they don't mix with
other types. Silently casting to other types is a big source of errors when
using float. I'm also including _sf, _sd _sld literal suffixes.
Best regards,
Damian