]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/example/example17.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / safe_numerics / example / example17.cpp
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
9 using namespace boost::safe_numerics;
10
11 uint8_t f(uint8_t i){
12 return i;
13 }
14
15 using safe_t = safe<long, native, loose_trap_policy>;
16
17 int main(){
18 const long x = 97;
19 f(x); // OK - implicit conversion to int can never fail
20 const safe_t y = 97;
21 f(y); // could overflow so trap at compile time
22 return 0;
23 }