example82.cpp 711 B

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