1 #ifndef BOOST_SAFE_NUMERICS_TEST_CHECKED_VALUES_HPP
2 #define BOOST_SAFE_NUMERICS_TEST_CHECKED_VALUES_HPP
3 
4 //  Copyright (c) 2018 Robert Ramey
5 //
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)
9 
10 #include <boost/safe_numerics/checked_result.hpp>
11 #include <boost/mp11/list.hpp>
12 #include <boost/mp11/algorithm.hpp>
13 
14 // values
15 // note: In theory explicity specifying the number of elements in the
16 // array should not be necessary.  However, this seems to crash the CLang
17 // compilers with standards setting of C++17.  So don't remove the array
18 // bounds below
19 template<typename T>
20 constexpr const boost::safe_numerics::checked_result<T> signed_values[9] = {
21     boost::safe_numerics::safe_numerics_error::range_error,
22     boost::safe_numerics::safe_numerics_error::domain_error,
23     boost::safe_numerics::safe_numerics_error::positive_overflow_error,
24     std::numeric_limits<T>::max(),
25     1,
26     0,
27     -1,
28     std::numeric_limits<T>::lowest(),
29     boost::safe_numerics::safe_numerics_error::negative_overflow_error,
30 };
31 
32 using signed_test_types = boost::mp11::mp_list<
33     std::int8_t, std::int16_t, std::int32_t, std::int64_t
34 >;
35 using signed_value_indices = boost::mp11::mp_iota_c<
36     sizeof(signed_values<int>) / sizeof(signed_values<int>[0])
37 >;
38 
39 template<typename T>
40 constexpr const boost::safe_numerics::checked_result<T> unsigned_values[7] = {
41     boost::safe_numerics::safe_numerics_error::range_error,
42     boost::safe_numerics::safe_numerics_error::domain_error,
43     boost::safe_numerics::safe_numerics_error::positive_overflow_error,
44     std::numeric_limits<T>::max(),
45     1,
46     0,
47     boost::safe_numerics::safe_numerics_error::negative_overflow_error,
48 };
49 
50 using unsigned_test_types = boost::mp11::mp_list<
51     std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t
52 >;
53 using unsigned_value_indices = boost::mp11::mp_iota_c<
54     sizeof(unsigned_values<int>) / sizeof(unsigned_values<int>[0])
55 >;
56 
57 #endif // BOOST_SAFE_NUMERICS_TEST_CHECKED_VALUES_HPP
58