]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/test/test_auto.cpp
3 #include <boost/core/demangle.hpp>
5 #include <boost/safe_numerics/safe_integer.hpp>
6 #include <boost/safe_numerics/safe_integer_range.hpp>
7 #include <boost/safe_numerics/automatic.hpp>
8 #include <boost/safe_numerics/utility.hpp>
11 using namespace boost::safe_numerics::utility
;
12 assert(ilog2(127u) == 6);
13 assert(ilog2(128u) == 7);
14 assert(ilog2(129u) == 7);
15 assert(ilog2(255u) == 7);
16 assert(ilog2(256u) == 8);
18 assert(ilog2(127) == 6);
19 assert(ilog2(128) == 7);
20 assert(ilog2(129) == 7);
21 assert(ilog2(255) == 7);
22 assert(ilog2(256) == 8);
27 void print_argument_type(const T
& t
){
28 const std::type_info
& ti
= typeid(T
);
30 << boost::core::demangle(ti
.name()) << ' ' << t
<< std::endl
;
33 template<typename T
, typename U
>
34 int test_auto(const T
& t
, const U
& u
){
35 using namespace boost::safe_numerics
;
38 safe
<T
, automatic
>(t
) + u
;
40 catch(const std::exception
&){
41 safe
<T
, automatic
>(t
) + u
;
45 t
+ safe
<U
, automatic
>(u
);
47 catch(const std::exception
&){
48 t
+ safe
<U
, automatic
>(u
);
53 int test_auto_result(){
54 using namespace boost::safe_numerics
;
55 automatic::addition_result
<
56 safe
<std::int8_t, automatic
>,
57 safe
<std::uint16_t, automatic
>
59 print_argument_type(r1
);
61 automatic::addition_result
<
62 safe_signed_range
<-3, 8, automatic
>,
63 safe_signed_range
<-4, 9, automatic
>
65 print_argument_type(r2
);
69 int test_compare_result(){
70 using namespace boost::safe_numerics
;
72 automatic::comparison_result
<
73 safe
<std::int16_t, automatic
>,
74 safe
<std::int16_t, automatic
>
76 print_argument_type(r1
);
82 using namespace boost::safe_numerics
;
85 test_auto
<std::int8_t, std::int8_t>(1, -128);
87 test_compare_result();