1 #ifndef BOOST_TEST_LEFT_SHIFT_HPP
2 #define BOOST_TEST_LEFT_SHIFT_HPP
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)
12 #include <boost/safe_numerics/safe_integer.hpp>
13 #include <boost/safe_numerics/range_value.hpp>
15 template<class T1, class T2>
25 << av1 << " << " << av2
29 using result_type = decltype(t1 << v2);
30 std::cout << "safe<" << av1 << "> << " << av2 << " -> ";
32 boost::safe_numerics::is_safe<result_type>::value,
33 "Expression failed to return safe type"
36 // use auto to avoid checking assignment.
37 auto result = t1 << v2;
38 std::cout << make_result_display(result);
39 if(expected_result == 'x'){
41 << " ! = "<< av1 << " << " << av2
42 << " failed to detect arithmetic error in left shift"
47 std::cout << std::endl;
49 catch(const std::exception & e){
50 if(expected_result == '.'){
52 << "erroneously detected arithmetic error in left shift"
53 << " == "<< av1 << " << " << av2
59 catch(const std::exception &){}
62 std::cout << std::endl;
67 using result_type = decltype(v1 << t2);
68 std::cout << av1 << " << " << "safe<" << av2 << "> -> ";
70 boost::safe_numerics::is_safe<result_type>::value,
71 "Expression failed to return safe type"
75 // use auto to avoid checking assignment.
76 auto result = v1 << t2;
77 std::cout << make_result_display(result);
78 if(expected_result == 'x'){
80 << " ! = "<< av1 << " << " << av2
81 << " failed to detect error in left shift"
82 << std::hex << result << "(" << std::dec << result << ")"
87 std::cout << std::endl;
89 catch(const std::exception & e){
90 if(expected_result == '.'){
92 << " == "<< av1 << " << " << av2
93 << "erroneously detected error in left shift "
99 catch(const std::exception &){}
102 std::cout << std::endl;
108 using result_type = decltype(t1 << t2);
109 std::cout << "safe<" << av1 << "> << " << "safe<" << av2 << "> -> ";
111 boost::safe_numerics::is_safe<result_type>::value,
112 "Expression failed to return safe type"
116 // use auto to avoid checking assignment.
117 auto result = t1 << t2;
118 std::cout << make_result_display(result);
119 if(expected_result == 'x'){
121 << " ! = "<< av1 << " << " << av2
122 << " failed to detect error in left shift"
127 std::cout << std::endl;
129 catch(const std::exception & e){
130 if(expected_result == '.'){
132 << " == "<< av1 << " << " << av2
133 << " erroneously detected error in left shift"
139 catch(const std::exception &){}
142 std::cout << std::endl;
145 return true; // correct result
148 #endif // BOOST_TEST_DIVIDE