]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/example/example6.cpp
5 #include <boost/safe_numerics/safe_integer.hpp>
7 int main(int, const char *[]){
8 // problem: checking of externally produced value can be overlooked
9 std::cout
<< "example 6: ";
10 std::cout
<< "checking of externally produced value can be overlooked" << std::endl
;
11 std::cout
<< "Not using safe numerics" << std::endl
;
13 std::istringstream
is("12317289372189 1231287389217389217893");
17 is
>> x
>> y
; // get integer values from the user
18 std::cout
<< x
<< ' ' << y
<< std::endl
;
19 std::cout
<< "error NOT detected!" << std::endl
;
21 catch(const std::exception
&){
22 std::cout
<< "error detected!" << std::endl
;
25 // solution: assign externally retrieved values to safe equivalents
26 std::cout
<< "Using safe numerics" << std::endl
;
28 using namespace boost::safe_numerics
;
32 is
>> x
>> y
; // get integer values from the user
33 std::cout
<< x
<< ' ' << y
<< std::endl
;
34 std::cout
<< "error NOT detected!" << std::endl
;
36 catch(const std::exception
& e
){
37 std::cout
<< "error detected:" << e
.what() << std::endl
;