1 // Copyright (c) 2012 Robert Ramey
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
8 #include <boost/logic/tribool_io.hpp>
10 #include <boost/core/demangle.hpp>
11 #include <boost/safe_numerics/checked_result_operations.hpp>
12 #include <boost/safe_numerics/checked_integer.hpp>
14 // works for both GCC and clang
15 #pragma GCC diagnostic push
16 #pragma GCC diagnostic ignored "-Wunused-value"
18 // note: T should be of type checked_result<R> for some integer type R
20 bool test_checked_less_than(
25 using namespace boost::safe_numerics
;
26 const boost::logic::tribool result
= v1
< v2
;
28 << std::boolalpha
<< v1
<< " < " << v2
<< " -> " << result
31 switch(expected_result
){
42 if(indeterminate(result
))
47 << "failed to detect error in addition "
48 << std::hex
<< result
<< "(" << std::dec
<< result
<< ")"
49 << " != "<< v1
<< " < " << v2
55 #pragma GCC diagnostic pop
57 #include "test_checked_comparison.hpp"
59 template<typename T
, typename First
, typename Second
>
60 struct test_signed_pair
{
61 bool operator()() const {
62 std::size_t i
= First();
63 std::size_t j
= Second();
64 std::cout
<< std::dec
<< i
<< ',' << j
<< ','
65 << "testing " << boost::core::demangle(typeid(T
).name()) << ' ';
66 return test_checked_less_than(
69 signed_comparison_results
[i
][j
]
74 template<typename T
, typename First
, typename Second
>
75 struct test_unsigned_pair
{
76 bool operator()() const {
77 std::size_t i
= First();
78 std::size_t j
= Second();
79 std::cout
<< std::dec
<< i
<< ',' << j
<< ','
80 << "testing " << boost::core::demangle(typeid(T
).name()) << ' ';
81 return test_checked_less_than(
82 unsigned_values
<T
>[i
],
83 unsigned_values
<T
>[j
],
84 unsigned_comparison_results
[i
][j
]
89 #include <boost/mp11/algorithm.hpp>
92 using namespace boost::mp11
;
110 unsigned_value_indices
, unsigned_value_indices
116 std::cout
<< (rval
? "success!" : "failure") << std::endl
;