example81.cpp 514 B

123456789101112131415161718
  1. #include <iostream>
  2. #include <boost/safe_numerics/safe_integer.hpp>
  3. #include <boost/safe_numerics/exception_policies.hpp> // include exception policies
  4. using safe_t = boost::safe_numerics::safe<
  5. int,
  6. boost::safe_numerics::native,
  7. boost::safe_numerics::loose_trap_policy // note use of "loose_trap_exception" policy!
  8. >;
  9. int main(int argc, const char * argv[]){
  10. std::cout << "example 81:\n";
  11. safe_t x(INT_MAX);
  12. safe_t y(2);
  13. safe_t z = x + y; // will fail to compile !
  14. return 0;
  15. }