1// Copyright (c) 2018 Robert Ramey
2//
3// Distributed under the Boost Software License, Version 1.0. (See
4// accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#include <boost/safe_numerics/safe_integer.hpp>
8#include <cstdint> // uint8_t
9using namespace boost::safe_numerics;
10
11uint8_t f(uint8_t i){
12 return i;
13}
14
15using safe_t = safe<long, native, loose_trap_policy>;
16
17int main(){
18 const long x = 97;
19 f(i: x); // OK - implicit conversion to int can never fail
20 const safe_t y = 97;
21 f(i: y); // could overflow so trap at compile time
22 return 0;
23}
24

source code of boost/libs/safe_numerics/example/example17.cpp