]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/example/example91.cpp
1 //////////////////////////////////////////////////////////////////
4 // Copyright (c) 2015 Robert Ramey
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
13 #include <boost/safe_numerics/cpp.hpp>
14 #include <boost/safe_numerics/safe_integer.hpp>
15 #include <boost/safe_numerics//safe_integer_range.hpp>
17 // use same type promotion as used by the pic compiler
18 // see the following comment in motor.c
19 // Types: int8,int16,int32=8,16,32bit integers
21 using pic16_promotion
= boost::safe_numerics::cpp
<
29 // define safe types used desktop version of the program. In conjunction
30 // with the promotion policy above, this will permit us to guarantee that
31 // the resulting program will be free of arithmetic errors introduced by
32 // C expression syntax and type promotion with no runtime penalty
33 template <typename T
> // T is char, int, etc data type
34 using safe_t
= boost::safe_numerics::safe
<
37 boost::safe_numerics::default_exception_policy
// use for compiling and running tests
39 using safe_bool_t
= boost::safe_numerics::safe_unsigned_range
<
43 boost::safe_numerics::default_exception_policy
// use for compiling and running tests
53 std::this_thread::sleep_for(std::chrono::microseconds(ccpr
));
57 std::cout
<< "start test\n";
65 // move motor to position 1000
72 // move back to position 0
79 catch(std::exception
& e
){
80 std::cout
<< e
.what() << '\n';
81 // we expect to trap an exception
85 std::cout
<< "test interrupted\n";
88 std::cout
<< "end test\n";