]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/test/test_safe_compare.cpp
1 // Copyright (c) 2014 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)
9 #include <boost/core/demangle.hpp>
10 #include <boost/safe_numerics/safe_compare.hpp>
12 template<class T1
, class T2
>
13 void print_argument_types(
17 const std::type_info
& ti1
= typeid(v1
);
18 const std::type_info
& ti2
= typeid(v2
);
21 << boost::core::demangle(ti1
.name()) << ','
22 << boost::core::demangle(ti2
.name());
25 #include <boost/mp11/algorithm.hpp>
27 using namespace boost::safe_numerics
;
29 template<class T1
, class T2
>
30 bool test_safe_compare_impl(
35 switch(expected_result
){
37 if(! safe_compare::equal(v1
, v2
))
39 if(safe_compare::less_than(v1
, v2
))
41 if(safe_compare::greater_than(v1
, v2
))
46 if(! safe_compare::less_than(v1
, v2
))
48 if(safe_compare::greater_than(v1
, v2
))
50 if(safe_compare::equal(v1
, v2
))
55 if(! safe_compare::greater_than(v1
, v2
))
57 if(safe_compare::less_than(v1
, v2
))
59 if(safe_compare::equal(v1
, v2
))
67 template<class T1
, class T2
>
68 bool test_safe_compare(
73 print_argument_types(v1
, v2
);
74 const bool result
= test_safe_compare_impl(v1
, v2
, expected_result
);
76 std::cout
<< " failed";
81 #include "test_values.hpp"
83 const char *test_compare_result
[boost::mp11::mp_size
<test_values
>::value
] = {
85 // 012345670123456701234567012345670
86 // 012345678901234567890123456789012
87 /* 0*/ "=<>>=<>>=<>>=<>>=<<<=<<<=<<<=<<<>",
88 /* 1*/ ">=>>><>>><>>><>>>=<<><<<><<<><<<>",
89 /* 2*/ "<<=<<<><<<><<<><<<<<<<<<<<<<<<<<<",
90 /* 3*/ "<<>=<<>=<<>=<<>=<<<<<<<<<<<<<<<<<",
91 /* 4*/ "=<>>=<>>=<>>=<>>=<<<=<<<=<<<=<<<>",
92 /* 5*/ ">>>>>=>>><>>><>>>>>>>=<<><<<><<<>",
93 /* 6*/ "<<<<<<=<<<><<<><<<<<<<<<<<<<<<<<<",
94 /* 7*/ "<<>=<<>=<<>=<<>=<<<<<<<<<<<<<<<<<",
96 /* 8*/ "=<>>=<>>=<>>=<>>=<<<=<<<=<<<=<<<>",
97 /* 9*/ ">>>>>>>>>=>>><>>>>>>>>>>>=<<><<<>",
98 /*10*/ "<<<<<<<<<<=<<<><<<<<<<<<<<<<<<<<<",
99 /*11*/ "<<>=<<>=<<>=<<>=<<<<<<<<<<<<<<<<<",
100 /*12*/ "=<>>=<>>=<>>=<>>=<<<=<<<=<<<=<<<>",
101 /*13*/ ">>>>>>>>>>>>>=>>>>>>>>>>>>>>>=<<>",
102 /*14*/ "<<<<<<<<<<<<<<=<<<<<<<<<<<<<<<<<<",
103 /*15*/ "<<>=<<>=<<>=<<>=<<<<<<<<<<<<<<<<",
106 // 012345670123456701234567012345670
107 // 012345678901234567890123456789012
108 /*16*/ "=<>>=<>>=<>>=<>>=<<<=<<<=<<<=<<<>",
109 /*17*/ ">=>>><>>><>>><>>>=<<><<<><<<><<<>",
110 /*18*/ ">>>>><>>><>>><>>>>=<><<<><<<><<<>",
111 /*19*/ ">>>>><>>><>>><>>>>>=><<<><<<><<<>",
112 /*20*/ "=<>>=<>>=<>>=<>>=<<<=<<<=<<<=<<<>",
113 /*21*/ ">>>>>=>>><>>><>>>>>>>=<<><<<><<<>",
114 /*22*/ ">>>>>>>>><>>><>>>>>>>>=<><<<><<<>",
115 /*23*/ ">>>>>>>>><>>><>>>>>>>>>=><<<><<<>",
117 /*24*/ "=<>>=<>>=<>>=<>>=<<<=<<<=<<<=<<<>",
118 /*25*/ ">>>>>>>>>=>>><>>>>>>>>>>>=<<><<<>",
119 /*26*/ ">>>>>>>>>>>>><>>>>>>>>>>>>=<><<<>",
120 /*27*/ ">>>>>>>>>>>>><>>>>>>>>>>>>>=><<<>",
121 /*28*/ "=<>>=<>>=<>>=<>>=<<<=<<<=<<<=<<<>",
122 /*29*/ ">>>>>>>>>>>>>=>>>>>>>>>>>>>>>=<<>",
123 /*30*/ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>=<>",
124 /*31*/ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>=>",
125 /*32*/ "<<>><<>><<>><<>><<<<<<<<<<<<<<<<="
128 using namespace boost::mp11
;
132 static_assert(mp_is_list
<L
>(), "must be a list of integral constants");
134 test(bool b
= true) : m_error(b
) {}
139 void operator()(const T
&){
140 static_assert(mp_is_list
<T
>(), "must be a list of two integral constants");
141 constexpr size_t i1
= mp_first
<T
>(); // index of first argument
142 constexpr size_t i2
= mp_second
<T
>();// index of second argument
143 std::cout
<< i1
<< ',' << i2
<< ',';
144 using T1
= typename
boost::mp11::mp_at_c
<L
, i1
>::value_type
;
145 using T2
= typename
boost::mp11::mp_at_c
<L
, i2
>::value_type
;
146 m_error
&= test_safe_compare
<T1
, T2
>(
147 boost::mp11::mp_at_c
<L
, i1
>(), // value of first argument
148 boost::mp11::mp_at_c
<L
, i2
>(), // value of second argument
149 test_compare_result
[i1
][i2
]
155 //TEST_EACH_VALUE_PAIR
156 test
<test_values
> rval(true);
158 using value_indices
= mp_iota_c
<mp_size
<test_values
>::value
>;
160 mp_product
<mp_list
, value_indices
, value_indices
>
163 std::cout
<< (rval
? "success!" : "failure") << std::endl
;