]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/test/test_checked_modulus_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)
7 #include <boost/safe_numerics/checked_result.hpp>
8 #include <boost/safe_numerics/checked_result_operations.hpp>
9 #include <boost/safe_numerics/checked_integer.hpp>
12 constexpr bool test_checked_modulus(
17 using namespace boost::safe_numerics
;
18 const T result
= v1
% v2
;
19 switch(expected_result
){
22 return ! result
.exception();
24 return safe_numerics_error::negative_overflow_error
== result
.m_e
;
26 return safe_numerics_error::positive_overflow_error
== result
.m_e
;
28 return safe_numerics_error::range_error
== result
.m_e
;
33 #include "test_checked_modulus.hpp"
35 #include <boost/mp11/algorithm.hpp>
37 template<typename T
, typename First
, typename Second
>
38 struct test_signed_pair
{
39 static const std::size_t i
= First();
40 static const std::size_t j
= Second();
41 // note: is constexpr really required here? compilers disagree!
42 constexpr static const bool value
= test_checked_modulus(
45 signed_modulus_results
[i
][j
]
49 template<typename T
, typename First
, typename Second
>
50 struct test_unsigned_pair
{
51 static const std::size_t i
= First();
52 static const std::size_t j
= Second();
53 // note: is constexpr really required here? compilers disagree!
54 constexpr static const bool value
= test_checked_modulus(
55 unsigned_values
<T
>[i
],
56 unsigned_values
<T
>[j
],
57 unsigned_modulus_results
[i
][j
]
61 #include <boost/mp11/algorithm.hpp>
62 #include <boost/mp11/function.hpp>
65 using namespace boost::mp11
;
71 signed_value_indices
, signed_value_indices
75 "modulus for all signed values correct"
83 unsigned_value_indices
, unsigned_value_indices
87 "modulus for all unsigned values correct"