]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/test/test_checked_xor_constexpr.cpp
1 // Copyright (c) 2018 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/checked_result_operations.hpp>
11 #include <boost/safe_numerics/checked_integer.hpp>
13 // note: T should be of tyme checked_result<R> for some integer type R
15 constexpr bool test_checked_xor(
20 using namespace boost::safe_numerics
;
21 const T result
= v1
^ v2
;
23 switch(expected_result
){
25 if(result
.exception()){
30 if(safe_numerics_error::negative_overflow_error
== result
.m_e
)
33 if(safe_numerics_error::positive_overflow_error
== result
.m_e
)
36 if(safe_numerics_error::range_error
== result
.m_e
)
42 #include "test_checked_xor.hpp"
44 template<typename T
, typename First
, typename Second
>
45 struct test_signed_pair
{
46 static const std::size_t i
= First();
47 static const std::size_t j
= Second();
48 static const bool value
= test_checked_xor(
51 signed_xor_results
[i
][j
]
55 template<typename T
, typename First
, typename Second
>
56 struct test_unsigned_pair
{
57 static const std::size_t i
= First();
58 static const std::size_t j
= Second();
59 // note: is constexpr really required here? compilers disagree!
60 constexpr static const bool value
= test_checked_xor(
61 unsigned_values
<T
>[i
],
62 unsigned_values
<T
>[j
],
63 unsigned_xor_results
[i
][j
]
67 #include "check_symmetry.hpp"
68 #include <boost/mp11/algorithm.hpp>
71 using namespace boost::mp11
;
72 check_symmetry(signed_xor_results
);
73 check_symmetry(unsigned_xor_results
);
80 signed_value_indices
, signed_value_indices
84 "all values for all signed types correctly xor'ed"
92 unsigned_value_indices
, unsigned_value_indices
96 "all values for all unsigned types correctly xor'ed"