example18.cpp 447 B

12345678910111213141516171819
  1. #include <boost/safe_numerics/safe_integer.hpp>
  2. #include <boost/safe_numerics/safe_integer_literal.hpp>
  3. using namespace boost::safe_numerics;
  4. int f(int i){
  5. return i;
  6. }
  7. template<intmax_t N>
  8. using safe_literal = safe_signed_literal<N, native, loose_trap_policy>;
  9. int main(){
  10. const long x = 97;
  11. f(x); // OK - implicit conversion to int
  12. const safe_literal<97> y;
  13. f(y); // OK - y is a type with min/max = 97;
  14. return 0;
  15. }