]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/test/test_auto.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / safe_numerics / test / test_auto.cpp
1 #include <iostream>
2 #include <cassert>
3 #include <boost/core/demangle.hpp>
4
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>
9
10 int test_log(){
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);
17
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);
23 return 0;
24 }
25
26 template<class T>
27 void print_argument_type(const T & t){
28 const std::type_info & ti = typeid(T);
29 std::cout
30 << boost::core::demangle(ti.name()) << ' ' << t << std::endl;
31 }
32
33 template<typename T, typename U>
34 int test_auto(const T & t, const U & u){
35 using namespace boost::safe_numerics;
36
37 try{
38 safe<T, automatic>(t) + u;
39 }
40 catch(const std::exception &){
41 safe<T, automatic>(t) + u;
42 }
43
44 try{
45 t + safe<U, automatic>(u);
46 }
47 catch(const std::exception &){
48 t + safe<U, automatic>(u);
49 }
50 return 0;
51 }
52
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>
58 >::type r1;
59 print_argument_type(r1);
60
61 automatic::addition_result<
62 safe_signed_range<-3, 8, automatic>,
63 safe_signed_range<-4, 9, automatic>
64 >::type r2;
65 print_argument_type(r2);
66 return 0;
67 }
68
69 int test_compare_result(){
70 using namespace boost::safe_numerics;
71
72 automatic::comparison_result<
73 safe<std::int16_t, automatic>,
74 safe<std::int16_t, automatic>
75 >::type r1;
76 print_argument_type(r1);
77
78 return 0;
79 }
80
81 int main(){
82 using namespace boost::safe_numerics;
83
84 test_log();
85 test_auto<std::int8_t, std::int8_t>(1, -128);
86 test_auto_result();
87 test_compare_result();
88 return 0;
89 }