1 #include <iostream> 2 3 #include <boost/safe_numerics/safe_integer.hpp> 4 #include <boost/safe_numerics/exception_policies.hpp> 5 #include <boost/safe_numerics/automatic.hpp> 6 #include "safe_format.hpp" // prints out range and value of any type 7 8 using safe_t = boost::safe_numerics::safe< 9 int, 10 boost::safe_numerics::automatic, // note use of "automatic" policy!!! 11 boost::safe_numerics::loose_trap_policy 12 >; 13 main(int,const char * [])14int main(int, const char *[]){ 15 std::cout << "example 82:\n"; 16 safe_t x(INT_MAX); 17 safe_t y = 2; 18 std::cout << "x = " << safe_format(x) << std::endl; 19 std::cout << "y = " << safe_format(y) << std::endl; 20 std::cout << "x + y = " << safe_format(x + y) << std::endl; 21 return 0; 22 } 23 24