test_checked_values.hpp 2.0 KB

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